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=9a8f2c2a6b4e6c077af0f3c55cbeaf5575cf91d6;hb=d142608024302ca4106a70b95daabf27aa5362a4;hp=5c908092d451ad98f6284ccc4b67cf5e40c5d42f;hpb=0b8fe498389b99374691506cb8c3bbb643476c3f;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 index 5c90809..9a8f2c2 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt @@ -1,8 +1,13 @@ package net.pterodactylus.sone.web.ajax +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.PostReply +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.never import org.mockito.Mockito.verify /** @@ -12,28 +17,48 @@ class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage @Test fun `request with invalid type results in invalid-type error`() { - addRequestParameter("type", "invalid") + 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`() { + fun `request with valid post id results in post being liked by current sone`() { addRequestParameter("type", "post") addRequestParameter("post", "post-id") + addPost(mock().apply { whenever(id).thenReturn("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`() { + fun `request with valid reply id results in reply being liked by current sone`() { addRequestParameter("type", "reply") addRequestParameter("reply", "reply-id") + addReply(mock().apply { whenever(id).thenReturn("reply-id") }) assertThat(json.isSuccess, equalTo(true)) verify(currentSone).addLikedReplyId("reply-id") verify(core).touchConfiguration() } + @Test + fun `request with invalid post id results in post being liked by current sone`() { + addRequestParameter("type", "post") + addRequestParameter("post", "post-id") + assertThat(json.isSuccess, equalTo(false)) + verify(currentSone, never()).addLikedPostId("post-id") + verify(core, never()).touchConfiguration() + } + + @Test + fun `request with invalid reply id results in reply being liked by current sone`() { + addRequestParameter("type", "reply") + addRequestParameter("reply", "reply-id") + assertThat(json.isSuccess, equalTo(false)) + verify(currentSone, never()).addLikedReplyId("reply-id") + verify(core, never()).touchConfiguration() + } + }