🔥 Remove “create” flag from session provider interface
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / DeleteReplyAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
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.*
8 import org.junit.*
9 import org.mockito.Mockito.*
10
11 /**
12  * Unit test for [DeleteReplyAjaxPage].
13  */
14 class DeleteReplyAjaxPageTest : JsonPageTest("deleteReply.ajax", pageSupplier = ::DeleteReplyAjaxPage) {
15
16         @Test
17         fun `request with missing reply results in invalid id`() {
18                 assertThatJsonFailed("invalid-reply-id")
19         }
20
21         @Test
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")
29         }
30
31         @Test
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)
41         }
42
43         @Test
44         fun `page can be created by dependency injection`() {
45             assertThat(baseInjector.getInstance<DeleteReplyAjaxPage>(), notNullValue())
46         }
47
48 }