mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fixes #3464, App posts deletion request notifications ({{subst:idw}}) on the wrong user's talk page (#3495)
* Fixed #3464: App posts deletion request notifications ({{subst:idw}}) on the wrong user's talk page * Fixed DeleteHelperTest.kt * Fixed DeleteHelper tests and null-pointer exception * Modified DeleteHelper makeDeletion() test * Reverted unintentionally modified Project.xml * Raising exception when nominating for deletion with empty creator name * Fixed code style * Fixed code style
This commit is contained in:
parent
cd2d530175
commit
e55b5495a1
2 changed files with 33 additions and 2 deletions
|
|
@ -98,6 +98,12 @@ public class DeleteHelper {
|
||||||
String userPageString = "\n{{subst:idw|" + media.getFilename() +
|
String userPageString = "\n{{subst:idw|" + media.getFilename() +
|
||||||
"}} ~~~~";
|
"}} ~~~~";
|
||||||
|
|
||||||
|
String creator = media.getCreator();
|
||||||
|
if (creator == null || creator.isEmpty()) {
|
||||||
|
throw new RuntimeException("Failed to nominate for deletion");
|
||||||
|
}
|
||||||
|
String creatorName = creator.replace(" (page does not exist)", "");
|
||||||
|
|
||||||
return pageEditClient.prependEdit(media.filename, fileDeleteString + "\n", summary)
|
return pageEditClient.prependEdit(media.filename, fileDeleteString + "\n", summary)
|
||||||
.flatMap(result -> {
|
.flatMap(result -> {
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|
@ -111,7 +117,7 @@ public class DeleteHelper {
|
||||||
throw new RuntimeException("Failed to nominate for deletion");
|
throw new RuntimeException("Failed to nominate for deletion");
|
||||||
}).flatMap(result -> {
|
}).flatMap(result -> {
|
||||||
if (result) {
|
if (result) {
|
||||||
return pageEditClient.appendEdit("User_Talk:" + username, userPageString + "\n", summary);
|
return pageEditClient.appendEdit("User_Talk:" + creatorName, userPageString + "\n", summary);
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Failed to nominate for deletion");
|
throw new RuntimeException("Failed to nominate for deletion");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package fr.free.nrw.commons.delete
|
package fr.free.nrw.commons.delete
|
||||||
|
|
||||||
import android.content.Context
|
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.Media
|
||||||
import fr.free.nrw.commons.actions.PageEditClient
|
import fr.free.nrw.commons.actions.PageEditClient
|
||||||
import fr.free.nrw.commons.notification.NotificationHelper
|
import fr.free.nrw.commons.notification.NotificationHelper
|
||||||
|
|
@ -14,7 +16,6 @@ import org.mockito.InjectMocks
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
import org.wikipedia.AppAdapter
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
|
|
||||||
|
|
@ -65,9 +66,13 @@ class DeleteHelperTest {
|
||||||
`when`(media?.displayTitle).thenReturn("Test file")
|
`when`(media?.displayTitle).thenReturn("Test file")
|
||||||
media?.filename="Test file.jpg"
|
media?.filename="Test file.jpg"
|
||||||
|
|
||||||
|
val creatorName = "Creator"
|
||||||
|
`when`(media?.getCreator()).thenReturn("$creatorName (page does not exist)")
|
||||||
|
|
||||||
val makeDeletion = deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
val makeDeletion = deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||||
assertNotNull(makeDeletion)
|
assertNotNull(makeDeletion)
|
||||||
assertTrue(makeDeletion!!)
|
assertTrue(makeDeletion!!)
|
||||||
|
verify(pageEditClient)?.appendEdit(eq("User_Talk:$creatorName"), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -83,6 +88,7 @@ class DeleteHelperTest {
|
||||||
.thenReturn(Observable.just(true))
|
.thenReturn(Observable.just(true))
|
||||||
`when`(media?.displayTitle).thenReturn("Test file")
|
`when`(media?.displayTitle).thenReturn("Test file")
|
||||||
`when`(media?.filename).thenReturn("Test file.jpg")
|
`when`(media?.filename).thenReturn("Test file.jpg")
|
||||||
|
`when`(media?.creator).thenReturn("Creator (page does not exist)")
|
||||||
|
|
||||||
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
@ -97,6 +103,7 @@ class DeleteHelperTest {
|
||||||
.thenReturn(Observable.just(false))
|
.thenReturn(Observable.just(false))
|
||||||
`when`(media?.displayTitle).thenReturn("Test file")
|
`when`(media?.displayTitle).thenReturn("Test file")
|
||||||
`when`(media?.filename).thenReturn("Test file.jpg")
|
`when`(media?.filename).thenReturn("Test file.jpg")
|
||||||
|
`when`(media?.creator).thenReturn("Creator (page does not exist)")
|
||||||
|
|
||||||
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +118,24 @@ class DeleteHelperTest {
|
||||||
.thenReturn(Observable.just(true))
|
.thenReturn(Observable.just(true))
|
||||||
`when`(media?.displayTitle).thenReturn("Test file")
|
`when`(media?.displayTitle).thenReturn("Test file")
|
||||||
`when`(media?.filename).thenReturn("Test file.jpg")
|
`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()
|
deleteHelper?.makeDeletion(context, media, "Test reason")?.blockingGet()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue