1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import org.hamcrest.MatcherAssert.*
7 import org.hamcrest.Matchers.*
9 import org.mockito.Mockito.*
12 * Unit test for [DeleteReplyAjaxPage].
14 class DeleteReplyAjaxPageTest : JsonPageTest("deleteReply.ajax", pageSupplier = ::DeleteReplyAjaxPage) {
17 fun `request with missing reply results in invalid id`() {
18 assertThatJsonFailed("invalid-reply-id")
22 fun `request with non-local reply id results in not authorized`() {
23 val reply = mock<PostReply>()
24 val sone = mock<Sone>()
25 whenever(reply.sone).thenReturn(sone)
26 addReply(reply, "reply-id")
27 addRequestParameter("reply", "reply-id")
28 assertThatJsonFailed("not-authorized")
32 fun `request with local reply id deletes reply`() {
33 val reply = mock<PostReply>()
34 val sone = mock<Sone>()
35 whenever(sone.isLocal).thenReturn(true)
36 whenever(reply.sone).thenReturn(sone)
37 addReply(reply, "reply-id")
38 addRequestParameter("reply", "reply-id")
39 assertThatJsonIsSuccessful()
40 verify(core).deleteReply(reply)
44 fun `page can be created by dependency injection`() {
45 assertThat(baseInjector.getInstance<DeleteReplyAjaxPage>(), notNullValue())