Replace follow Sone ajax page with Kotlin version
[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                 assertThat(json.isSuccess, equalTo(false))
20                 assertThat(json.error, equalTo("invalid-post-id"))
21         }
22
23         @Test
24         fun `post from non-local sone results in not authorized response`() {
25                 val post = mock<Post>()
26                 val sone = mock<Sone>()
27                 whenever(post.sone).thenReturn(sone)
28                 addPost("post-id", post)
29                 addRequestParameter("post", "post-id")
30                 assertThat(json.isSuccess, equalTo(false))
31                 assertThat(json.error, equalTo("not-authorized"))
32         }
33
34         @Test
35         fun `post from local sone is deleted`() {
36                 val post = mock<Post>()
37                 val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
38                 whenever(post.sone).thenReturn(sone)
39                 addPost("post-id", post)
40                 addRequestParameter("post", "post-id")
41                 assertThat(json.isSuccess, equalTo(true))
42                 verify(core).deletePost(post)
43         }
44
45 }