mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +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
				
			
		|  | @ -1,8 +1,10 @@ | |||
| package fr.free.nrw.commons.review | ||||
| 
 | ||||
| import com.nhaarman.mockitokotlin2.mock | ||||
| import com.nhaarman.mockitokotlin2.whenever | ||||
| import fr.free.nrw.commons.Media | ||||
| import fr.free.nrw.commons.media.MediaClient | ||||
| import io.reactivex.Completable | ||||
| import io.reactivex.Observable | ||||
| import io.reactivex.Single | ||||
| import org.junit.Assert.assertNull | ||||
|  | @ -17,7 +19,7 @@ import org.mockito.MockitoAnnotations | |||
| import org.wikipedia.dataclient.mwapi.MwQueryPage | ||||
| import org.wikipedia.dataclient.mwapi.MwQueryResponse | ||||
| import org.wikipedia.dataclient.mwapi.MwQueryResult | ||||
| import org.wikipedia.dataclient.mwapi.RecentChange | ||||
| import java.util.concurrent.Callable | ||||
| 
 | ||||
| /** | ||||
|  * Test class for ReviewHelper | ||||
|  | @ -32,6 +34,8 @@ class ReviewHelperTest { | |||
|     @InjectMocks | ||||
|     var reviewHelper: ReviewHelper? = null | ||||
| 
 | ||||
|     val dao = mock(ReviewDao::class.java) | ||||
| 
 | ||||
|     /** | ||||
|      * Init mocks | ||||
|      */ | ||||
|  | @ -45,16 +49,12 @@ class ReviewHelperTest { | |||
|         `when`(mockRevision.user).thenReturn("TestUser") | ||||
|         `when`(mwQueryPage.revisions()).thenReturn(listOf(mockRevision)) | ||||
| 
 | ||||
|         val recentChange = getMockRecentChange("log", "File:Test1.jpeg", 0) | ||||
|         val recentChange1 = getMockRecentChange("log", "File:Test2.png", 0) | ||||
|         val recentChange2 = getMockRecentChange("log", "File:Test3.jpg", 0) | ||||
|         val mwQueryResult = mock(MwQueryResult::class.java) | ||||
|         `when`(mwQueryResult.recentChanges).thenReturn(listOf(recentChange, recentChange1, recentChange2)) | ||||
|         `when`(mwQueryResult.firstPage()).thenReturn(mwQueryPage) | ||||
|         `when`(mwQueryResult.pages()).thenReturn(listOf(mwQueryPage)) | ||||
|         val mockResponse = mock(MwQueryResponse::class.java) | ||||
|         `when`(mockResponse.query()).thenReturn(mwQueryResult) | ||||
|         `when`(reviewInterface?.getRecentChanges(ArgumentMatchers.anyString())) | ||||
|         `when`(reviewInterface?.getRecentChanges()) | ||||
|                 .thenReturn(Observable.just(mockResponse)) | ||||
| 
 | ||||
|         `when`(reviewInterface?.getFirstRevisionOfFile(ArgumentMatchers.anyString())) | ||||
|  | @ -78,7 +78,7 @@ class ReviewHelperTest { | |||
|                 .thenReturn(Single.just(false)) | ||||
| 
 | ||||
|         reviewHelper?.randomMedia | ||||
|         verify(reviewInterface, times(1))!!.getRecentChanges(ArgumentMatchers.anyString()) | ||||
|         verify(reviewInterface, times(1))!!.getRecentChanges() | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | @ -90,7 +90,7 @@ class ReviewHelperTest { | |||
|                 .thenReturn(Single.just(true)) | ||||
|         val media = reviewHelper?.randomMedia?.blockingGet() | ||||
|         assertNull(media) | ||||
|         verify(reviewInterface, times(1))!!.getRecentChanges(ArgumentMatchers.anyString()) | ||||
|         verify(reviewInterface, times(1))!!.getRecentChanges() | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | @ -106,15 +106,7 @@ class ReviewHelperTest { | |||
|                 .thenReturn(Single.just(true)) | ||||
| 
 | ||||
|         reviewHelper?.randomMedia | ||||
|         verify(reviewInterface, times(1))!!.getRecentChanges(ArgumentMatchers.anyString()) | ||||
|     } | ||||
| 
 | ||||
|     private fun getMockRecentChange(type: String, title: String, oldRevisionId: Long): RecentChange { | ||||
|         val recentChange = mock(RecentChange::class.java) | ||||
|         `when`(recentChange!!.type).thenReturn(type) | ||||
|         `when`(recentChange.title).thenReturn(title) | ||||
|         `when`(recentChange.oldRevisionId).thenReturn(oldRevisionId) | ||||
|         return recentChange | ||||
|         verify(reviewInterface, times(1))!!.getRecentChanges() | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | @ -126,4 +118,53 @@ class ReviewHelperTest { | |||
| 
 | ||||
|         assertTrue(firstRevisionOfFile is MwQueryPage.Revision) | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Test the review status of the image | ||||
|      *  Case 1: Image identifier exists in the database | ||||
|      */ | ||||
|     @Test | ||||
|     fun getReviewStatusWhenImageHasBeenReviewedAlready() { | ||||
|         val testImageId1 = "123456" | ||||
|         `when`(dao.isReviewedAlready(testImageId1)).thenReturn(true) | ||||
| 
 | ||||
|         val observer = io.reactivex.observers.TestObserver<Boolean>() | ||||
|         Observable.fromCallable(Callable<Boolean> { | ||||
|             dao.isReviewedAlready(testImageId1) | ||||
|         }).subscribeWith(observer) | ||||
|         observer.assertValue(true) | ||||
|         observer.dispose() | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Test the review status of the image | ||||
|      *  Case 2: Image identifier does not exist in the database | ||||
|      */ | ||||
|     @Test | ||||
|     fun getReviewStatusWhenImageHasBeenNotReviewedAlready() { | ||||
|         val testImageId2 = "789101" | ||||
|         `when`(dao.isReviewedAlready(testImageId2)).thenReturn(false) | ||||
| 
 | ||||
|         val observer = io.reactivex.observers.TestObserver<Boolean>() | ||||
|         Observable.fromCallable(Callable<Boolean> { | ||||
|             dao.isReviewedAlready(testImageId2) | ||||
|         }).subscribeWith(observer) | ||||
|         observer.assertValue(false) | ||||
|         observer.dispose() | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Test the successful insertion of the image identifier into the database | ||||
|      */ | ||||
|     @Test | ||||
|     fun addViewedImagesToDB() { | ||||
|         val testImageId = "123456" | ||||
| 
 | ||||
|         val observer = io.reactivex.observers.TestObserver<Boolean>() | ||||
|         Completable.fromAction { | ||||
|             dao.insert(ReviewEntity(testImageId)) | ||||
|         }.subscribeWith(observer) | ||||
|         observer.assertComplete() | ||||
|         observer.dispose() | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ritika Pahwa
						Ritika Pahwa