Fix image not loading issue in peer review (#2902)

* Fix image loading issue in peer review

* With more test cases
This commit is contained in:
Vivek Maskara 2019-04-20 13:12:09 +05:30 committed by neslihanturan
parent 482cad6663
commit accb880256
2 changed files with 20 additions and 4 deletions

View file

@ -46,10 +46,10 @@ public class ReviewHelper {
.flatMap(title -> mediaWikiApi.pageExists("Commons:Deletion_requests/" + title)
.map(pageExists -> new Pair<>(title, pageExists)))
.map((Pair<String, Boolean> pair) -> {
if (pair.second) {
if (!pair.second) {
return new Media(pair.first.replace("File:", ""));
}
throw new Exception("Page does not exist");
throw new Exception("Already nominated for deletion");
}).retry(MAX_RANDOM_TRIES);
}
@ -58,7 +58,7 @@ public class ReviewHelper {
}
@Nullable
public String findImageInRecentChanges(List<RecentChange> recentChanges) {
private String findImageInRecentChanges(List<RecentChange> recentChanges) {
String imageTitle;
Random r = new Random();
int count = recentChanges.size();

View file

@ -50,12 +50,28 @@ class ReviewHelperTest {
.thenReturn(Single.just(listOf(recentChange, recentChange1, recentChange2)))
`when`(mediaWikiApi?.pageExists(ArgumentMatchers.anyString()))
.thenReturn(Single.just(true))
.thenReturn(Single.just(false))
val randomMedia = reviewHelper?.randomMedia?.blockingGet()
assertTrue(randomMedia is Media)
}
/**
* Test scenario when all media is already nominated for deletion
*/
@Test(expected = Exception::class)
fun getRandomMediaWithWithAllMediaNominatedForDeletion() {
val recentChange = getMockRecentChange("test", "File:Test1.jpeg", 0)
val recentChange1 = getMockRecentChange("test", "File:Test2.png", 0)
val recentChange2 = getMockRecentChange("test", "File:Test3.jpg", 0)
`when`(okHttpJsonApiClient?.recentFileChanges)
.thenReturn(Single.just(listOf(recentChange, recentChange1, recentChange2)))
`when`(mediaWikiApi?.pageExists(ArgumentMatchers.anyString()))
.thenReturn(Single.just(true))
reviewHelper?.randomMedia?.blockingGet()
}
fun getMockRecentChange(type: String, title: String, oldRevisionId: Long): RecentChange {
val recentChange = mock(RecentChange::class.java)
`when`(recentChange!!.type).thenReturn(type)