Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3464, App posts deletion request notifications ({{subst:idw}}) on the wrong user's talk page #3495

Merged
merged 9 commits into from
Mar 17, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ private Observable<Boolean> delete(Media media, String reason) {
String userPageString = "\n{{subst:idw|" + media.getFilename() +
"}} ~~~~";

String creator = media.getCreator();
if (creator == null || creator.isEmpty())
VitalyVPinchuk marked this conversation as resolved.
Show resolved Hide resolved
throw new RuntimeException("Failed to nominate for deletion");
String creatorName = creator.replace(" (page does not exist)", "");

return pageEditClient.prependEdit(media.filename, fileDeleteString + "\n", summary)
.flatMap(result -> {
if (result) {
Expand All @@ -111,7 +116,7 @@ private Observable<Boolean> delete(Media media, String reason) {
throw new RuntimeException("Failed to nominate for deletion");
}).flatMap(result -> {
if (result) {
return pageEditClient.appendEdit("User_Talk:" + username, userPageString + "\n", summary);
return pageEditClient.appendEdit("User_Talk:" + creatorName, userPageString + "\n", summary);
VitalyVPinchuk marked this conversation as resolved.
Show resolved Hide resolved
}
throw new RuntimeException("Failed to nominate for deletion");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fr.free.nrw.commons.delete

import android.content.Context
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.verify
import fr.free.nrw.commons.Media
import fr.free.nrw.commons.actions.PageEditClient
import fr.free.nrw.commons.notification.NotificationHelper
Expand All @@ -14,7 +16,6 @@ import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations
import org.wikipedia.AppAdapter
import javax.inject.Inject
import javax.inject.Named

Expand Down Expand Up @@ -65,9 +66,14 @@ class DeleteHelperTest {
`when`(media?.displayTitle).thenReturn("Test file")
media?.filename="Test file.jpg"

val creatorName = "Creator"
val noPageSuffix = " (page does not exist)"
VitalyVPinchuk marked this conversation as resolved.
Show resolved Hide resolved
`when`(media?.getCreator()).thenReturn("$creatorName$noPageSuffix")

VitalyVPinchuk marked this conversation as resolved.
Show resolved Hide resolved
val makeDeletion = deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
assertNotNull(makeDeletion)
assertTrue(makeDeletion!!)
verify(pageEditClient)?.appendEdit(eq("User_Talk:$creatorName"), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())
}

/**
Expand All @@ -83,6 +89,7 @@ class DeleteHelperTest {
.thenReturn(Observable.just(true))
`when`(media?.displayTitle).thenReturn("Test file")
`when`(media?.filename).thenReturn("Test file.jpg")
`when`(media?.creator).thenReturn("Creator (page does not exist)")

deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
}
Expand All @@ -97,6 +104,7 @@ class DeleteHelperTest {
.thenReturn(Observable.just(false))
`when`(media?.displayTitle).thenReturn("Test file")
`when`(media?.filename).thenReturn("Test file.jpg")
`when`(media?.creator).thenReturn("Creator (page does not exist)")

deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
}
Expand All @@ -111,6 +119,24 @@ class DeleteHelperTest {
.thenReturn(Observable.just(true))
`when`(media?.displayTitle).thenReturn("Test file")
`when`(media?.filename).thenReturn("Test file.jpg")
`when`(media?.creator).thenReturn("Creator (page does not exist)")

deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
}

@Test(expected = RuntimeException::class)
fun makeDeletionForEmptyCreatorName() {
`when`(pageEditClient?.prependEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
.thenReturn(Observable.just(true))
`when`(pageEditClient?.appendEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
.thenReturn(Observable.just(true))
`when`(pageEditClient?.edit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
.thenReturn(Observable.just(true))

`when`(media?.displayTitle).thenReturn("Test file")
media?.filename="Test file.jpg"

`when`(media?.getCreator()).thenReturn(null)

deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
}
Expand Down