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 assertThatJsonFailed("invalid-post-id")
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")
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)