Skip to content

Commit accb880

Browse files
maskaravivekneslihanturan
authored andcommitted
Fix image not loading issue in peer review (commons-app#2902)
* Fix image loading issue in peer review * With more test cases
1 parent 482cad6 commit accb880

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/src/main/java/fr/free/nrw/commons/review/ReviewHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ Single<Media> getRandomMedia() {
4646
.flatMap(title -> mediaWikiApi.pageExists("Commons:Deletion_requests/" + title)
4747
.map(pageExists -> new Pair<>(title, pageExists)))
4848
.map((Pair<String, Boolean> pair) -> {
49-
if (pair.second) {
49+
if (!pair.second) {
5050
return new Media(pair.first.replace("File:", ""));
5151
}
52-
throw new Exception("Page does not exist");
52+
throw new Exception("Already nominated for deletion");
5353
}).retry(MAX_RANDOM_TRIES);
5454
}
5555

@@ -58,7 +58,7 @@ Single<MwQueryPage.Revision> getFirstRevisionOfFile(String fileName) {
5858
}
5959

6060
@Nullable
61-
public String findImageInRecentChanges(List<RecentChange> recentChanges) {
61+
private String findImageInRecentChanges(List<RecentChange> recentChanges) {
6262
String imageTitle;
6363
Random r = new Random();
6464
int count = recentChanges.size();

app/src/test/kotlin/fr/free/nrw/commons/review/ReviewHelperTest.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,28 @@ class ReviewHelperTest {
5050
.thenReturn(Single.just(listOf(recentChange, recentChange1, recentChange2)))
5151

5252
`when`(mediaWikiApi?.pageExists(ArgumentMatchers.anyString()))
53-
.thenReturn(Single.just(true))
53+
.thenReturn(Single.just(false))
5454
val randomMedia = reviewHelper?.randomMedia?.blockingGet()
5555

5656
assertTrue(randomMedia is Media)
5757
}
5858

59+
/**
60+
* Test scenario when all media is already nominated for deletion
61+
*/
62+
@Test(expected = Exception::class)
63+
fun getRandomMediaWithWithAllMediaNominatedForDeletion() {
64+
val recentChange = getMockRecentChange("test", "File:Test1.jpeg", 0)
65+
val recentChange1 = getMockRecentChange("test", "File:Test2.png", 0)
66+
val recentChange2 = getMockRecentChange("test", "File:Test3.jpg", 0)
67+
`when`(okHttpJsonApiClient?.recentFileChanges)
68+
.thenReturn(Single.just(listOf(recentChange, recentChange1, recentChange2)))
69+
70+
`when`(mediaWikiApi?.pageExists(ArgumentMatchers.anyString()))
71+
.thenReturn(Single.just(true))
72+
reviewHelper?.randomMedia?.blockingGet()
73+
}
74+
5975
fun getMockRecentChange(type: String, title: String, oldRevisionId: Long): RecentChange {
6076
val recentChange = mock(RecentChange::class.java)
6177
`when`(recentChange!!.type).thenReturn(type)

0 commit comments

Comments
 (0)