1 package net.pterodactylus.sone.web.ajax
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.*
9 import org.mockito.Mockito.*
12 * Unit test for [DeletePostAjaxPage].
14 class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::DeletePostAjaxPage) {
17 fun `missing post ID results in invalid id response`() {
18 assertThatJsonFailed("invalid-post-id")
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")
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)
43 fun `page can be created by dependency injection`() {
44 assertThat(baseInjector.getInstance<DeletePostAjaxPage>(), notNullValue())