Move assertions to base class
[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.Post
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
9 import org.junit.Test
10 import org.mockito.Mockito.verify
11
12 /**
13  * Unit test for [DeletePostAjaxPage].
14  */
15 class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::DeletePostAjaxPage) {
16
17         @Test
18         fun `missing post ID results in invalid id response`() {
19                 assertThatJsonFailed("invalid-post-id")
20         }
21
22         @Test
23         fun `post from non-local sone results in not authorized response`() {
24                 val post = mock<Post>()
25                 val sone = mock<Sone>()
26                 whenever(post.sone).thenReturn(sone)
27                 addPost(post, "post-id")
28                 addRequestParameter("post", "post-id")
29                 assertThatJsonFailed("not-authorized")
30         }
31
32         @Test
33         fun `post from local sone is deleted`() {
34                 val post = mock<Post>()
35                 val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
36                 whenever(post.sone).thenReturn(sone)
37                 addPost(post, "post-id")
38                 addRequestParameter("post", "post-id")
39                 assertThatJsonIsSuccessful()
40                 verify(core).deletePost(post)
41         }
42
43 }