🔀 Merge branch 'release/v82'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / DeletePostAjaxPageTest.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 [DeletePostAjaxPage].
13  */
14 class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::DeletePostAjaxPage) {
15
16         @Test
17         fun `missing post ID results in invalid id response`() {
18                 assertThatJsonFailed("invalid-post-id")
19         }
20
21         @Test
22         fun `post from non-local sone results in not authorized response`() {
23                 val post = mock<Post>()
24                 val sone = mock<Sone>()
25                 whenever(post.sone).thenReturn(sone)
26                 addPost(post, "post-id")
27                 addRequestParameter("post", "post-id")
28                 assertThatJsonFailed("not-authorized")
29         }
30
31         @Test
32         fun `post from local sone is deleted`() {
33                 val post = mock<Post>()
34                 val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
35                 whenever(post.sone).thenReturn(sone)
36                 addPost(post, "post-id")
37                 addRequestParameter("post", "post-id")
38                 assertThatJsonIsSuccessful()
39                 verify(core).deletePost(post)
40         }
41
42         @Test
43         fun `page can be created by dependency injection`() {
44             assertThat(baseInjector.getInstance<DeletePostAjaxPage>(), notNullValue())
45         }
46
47 }