1 package net.pterodactylus.sone.web.ajax
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
10 import org.mockito.Mockito.verify
13 * Unit test for [DeletePostAjaxPage].
15 class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::DeletePostAjaxPage) {
18 fun `missing post ID results in invalid id response`() {
19 assertThat(json.isSuccess, equalTo(false))
20 assertThat(json.error, equalTo("invalid-post-id"))
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"))
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)