From: David ‘Bombe’ Roden Date: Thu, 14 Sep 2017 18:50:40 +0000 (+0200) Subject: Add test for like ajax page X-Git-Tag: 0.9.7^2~56 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=0b8fe498389b99374691506cb8c3bbb643476c3f Add test for like ajax page --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt new file mode 100644 index 0000000..5c90809 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt @@ -0,0 +1,39 @@ +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 [LikeAjaxPage]. + */ +class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage) { + + @Test + fun `request with invalid type results in invalid-type error`() { + addRequestParameter("type", "invalid") + addRequestParameter("invalid", "invalid-id") + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-type")) + } + + @Test + fun `request with post id results in post being liked by current sone`() { + addRequestParameter("type", "post") + addRequestParameter("post", "post-id") + assertThat(json.isSuccess, equalTo(true)) + verify(currentSone).addLikedPostId("post-id") + verify(core).touchConfiguration() + } + + @Test + fun `request with reply id results in reply being liked by current sone`() { + addRequestParameter("type", "reply") + addRequestParameter("reply", "reply-id") + assertThat(json.isSuccess, equalTo(true)) + verify(currentSone).addLikedReplyId("reply-id") + verify(core).touchConfiguration() + } + +}