X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FLikeAjaxPageTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FLikeAjaxPageTest.kt;h=5c908092d451ad98f6284ccc4b67cf5e40c5d42f;hb=0b8fe498389b99374691506cb8c3bbb643476c3f;hp=0000000000000000000000000000000000000000;hpb=1114ac09c29f29c4194f4ac9616d66d282e46329;p=Sone.git 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() + } + +}