mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
5161: Fix repeating images in peer review (#5170)
* fix API call to fetch the latest changes * add database table to keep a track of reviewed and skipped images * fix repeating reviewed or skipped images * add removed newline again * add necessary comments * change from timber.e to timber.i in case there is no exception * reintroduce the parameter rctag in the API URL * modify API URL to retrieve latest uploads * remove unused imports and code * modify ReviewHelperTest and add new unit tests * modify tests in ReviewHelperTest.kt * add comments about the value of gcmlimit
This commit is contained in:
parent
c920ef0371
commit
be1946cd7b
11 changed files with 268 additions and 98 deletions
|
|
@ -0,0 +1,74 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.room.Room;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import fr.free.nrw.commons.db.AppDatabase;
|
||||
import fr.free.nrw.commons.review.ReviewDao;
|
||||
import fr.free.nrw.commons.review.ReviewEntity;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ReviewDaoTest {
|
||||
|
||||
private ReviewDao reviewDao;
|
||||
private AppDatabase database;
|
||||
|
||||
/**
|
||||
* Set up the application database
|
||||
*/
|
||||
@Before
|
||||
public void createDb() {
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
database = Room.inMemoryDatabaseBuilder(
|
||||
context, AppDatabase.class)
|
||||
.allowMainThreadQueries()
|
||||
.build();
|
||||
reviewDao = database.ReviewDao();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the database
|
||||
*/
|
||||
@After
|
||||
public void closeDb() {
|
||||
database.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test insertion
|
||||
* Also checks isReviewedAlready():
|
||||
* Case 1: When image has been reviewed/skipped by the user
|
||||
*/
|
||||
@Test
|
||||
public void insert() {
|
||||
// Insert data
|
||||
String imageId = "1234";
|
||||
ReviewEntity reviewEntity = new ReviewEntity(imageId);
|
||||
reviewDao.insert(reviewEntity);
|
||||
|
||||
// Check insertion
|
||||
// Covers the case where the image exists in the database
|
||||
// And isReviewedAlready() returns true
|
||||
Boolean isInserted = reviewDao.isReviewedAlready(imageId);
|
||||
assertThat(isInserted, equalTo(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test review status of the image
|
||||
* Case 2: When image has not been reviewed/skipped
|
||||
*/
|
||||
@Test
|
||||
public void isReviewedAlready(){
|
||||
String imageId = "5856";
|
||||
Boolean isInserted = reviewDao.isReviewedAlready(imageId);
|
||||
assertThat(isInserted, equalTo(false));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue