From 38706924870dc8e85b70408dfc44eda45a606a68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 31 Aug 2017 20:31:32 +0200 Subject: [PATCH] Add test for delete post ajax page --- .../sone/web/ajax/DeletePostAjaxPageTest.kt | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPageTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPageTest.kt new file mode 100644 index 0000000..026b717 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/DeletePostAjaxPageTest.kt @@ -0,0 +1,45 @@ +package net.pterodactylus.sone.web.ajax + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test +import org.mockito.Mockito.verify + +/** + * Unit test for [DeletePostAjaxPage]. + */ +class DeletePostAjaxPageTest : JsonPageTest("deletePost.ajax", pageSupplier = ::DeletePostAjaxPage) { + + @Test + fun `missing post ID results in invalid id response`() { + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-post-id")) + } + + @Test + fun `post from non-local sone results in not authorized response`() { + val post = mock() + val sone = mock() + whenever(post.sone).thenReturn(sone) + addPost("post-id", post) + addRequestParameter("post", "post-id") + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("not-authorized")) + } + + @Test + fun `post from local sone is deleted`() { + val post = mock() + val sone = mock().apply { whenever(isLocal).thenReturn(true) } + whenever(post.sone).thenReturn(sone) + addPost("post-id", post) + addRequestParameter("post", "post-id") + assertThat(json.isSuccess, equalTo(true)) + verify(core).deletePost(post) + } + +} -- 2.7.4