From: David ‘Bombe’ Roden Date: Mon, 2 Oct 2017 13:27:58 +0000 (+0200) Subject: Add unit test for unlike ajax page X-Git-Tag: 0.9.7^2~38 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=eec3fc36611c32dd7a0f24be39239868befd2aeb;p=Sone.git Add unit test for unlike ajax page --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPageTest.kt new file mode 100644 index 0000000..ada19ba --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPageTest.kt @@ -0,0 +1,58 @@ +package net.pterodactylus.sone.web.ajax + +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test +import org.mockito.Mockito.verify + +/** + * Unit test for [UnlikeAjaxPage]. + */ +class UnlikeAjaxPageTest : JsonPageTest("unlike.ajax", pageSupplier = ::UnlikeAjaxPage) { + + @Test + fun `request without type results in error`() { + assertThat(json.isSuccess, equalTo(false)) + } + + @Test + fun `request for post without id results in invalid-post-id`() { + addRequestParameter("type", "post") + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-post-id")) + } + + @Test + fun `request for invalid type results in invalid-type`() { + addRequestParameter("type", "invalid") + addRequestParameter("invalid", "invalid") + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-type")) + } + + @Test + fun `request for post with id removes id from liked posts`() { + addRequestParameter("type", "post") + addRequestParameter("post", "post-id") + assertThat(json.isSuccess, equalTo(true)) + verify(currentSone).removeLikedPostId("post-id") + verify(core).touchConfiguration() + } + + @Test + fun `request for reply without id results in invalid-reply-id`() { + addRequestParameter("type", "reply") + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-reply-id")) + } + + @Test + fun `request for reply with id removes id from liked replys`() { + addRequestParameter("type", "reply") + addRequestParameter("reply", "reply-id") + assertThat(json.isSuccess, equalTo(true)) + verify(currentSone).removeLikedReplyId("reply-id") + verify(core).touchConfiguration() + } + +}