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.getInstance
6 import net.pterodactylus.sone.test.mock
7 import net.pterodactylus.sone.test.whenever
8 import net.pterodactylus.sone.web.baseInjector
9 import org.hamcrest.MatcherAssert.assertThat
10 import org.hamcrest.Matchers.equalTo
11 import org.hamcrest.Matchers.notNullValue
13 import org.mockito.Mockito.verify
16 * Unit test for [DeletePostAjaxPage].
18 class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::DeletePostAjaxPage) {
21 fun `missing post ID results in invalid id response`() {
22 assertThatJsonFailed("invalid-post-id")
26 fun `post from non-local sone results in not authorized response`() {
27 val post = mock<Post>()
28 val sone = mock<Sone>()
29 whenever(post.sone).thenReturn(sone)
30 addPost(post, "post-id")
31 addRequestParameter("post", "post-id")
32 assertThatJsonFailed("not-authorized")
36 fun `post from local sone is deleted`() {
37 val post = mock<Post>()
38 val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
39 whenever(post.sone).thenReturn(sone)
40 addPost(post, "post-id")
41 addRequestParameter("post", "post-id")
42 assertThatJsonIsSuccessful()
43 verify(core).deletePost(post)
47 fun `page can be created by dependency injection`() {
48 assertThat(baseInjector.getInstance<DeletePostAjaxPage>(), notNullValue())