1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.data.PostReply
4 import net.pterodactylus.sone.data.Sone
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.sone.test.whenever
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
10 import org.mockito.Mockito.verify
13 * Unit test for [DeleteReplyAjaxPage].
15 class DeleteReplyAjaxPageTest : JsonPageTest("deleteReply.ajax", pageSupplier = ::DeleteReplyAjaxPage) {
18 fun `request with missing reply results in invalid id`() {
19 assertThatJsonFailed("invalid-reply-id")
23 fun `request with non-local reply id results in not authorized`() {
24 val reply = mock<PostReply>()
25 val sone = mock<Sone>()
26 whenever(reply.sone).thenReturn(sone)
27 addReply(reply, "reply-id")
28 addRequestParameter("reply", "reply-id")
29 assertThatJsonFailed("not-authorized")
33 fun `request with local reply id deletes reply`() {
34 val reply = mock<PostReply>()
35 val sone = mock<Sone>()
36 whenever(sone.isLocal).thenReturn(true)
37 whenever(reply.sone).thenReturn(sone)
38 addReply(reply, "reply-id")
39 addRequestParameter("reply", "reply-id")
40 assertThatJsonIsSuccessful()
41 verify(core).deleteReply(reply)