X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FLikeAjaxPageTest.kt;h=c7da213a0172168a2ea161c9316af7b4b0def44c;hp=5c908092d451ad98f6284ccc4b67cf5e40c5d42f;hb=ea7ad5e87074576d17b7df74365a726bd95d7665;hpb=0b8fe498389b99374691506cb8c3bbb643476c3f 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..c7da213 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,16 @@ package net.pterodactylus.sone.web.ajax +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.PostReply +import net.pterodactylus.sone.test.getInstance +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever +import net.pterodactylus.sone.web.baseInjector import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.notNullValue import org.junit.Test +import org.mockito.Mockito.never import org.mockito.Mockito.verify /** @@ -12,28 +20,52 @@ 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")) + assertThatJsonFailed("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") - assertThat(json.isSuccess, equalTo(true)) + addPost(mock().apply { whenever(id).thenReturn("post-id") }) + assertThatJsonIsSuccessful() 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") - assertThat(json.isSuccess, equalTo(true)) + addReply(mock().apply { whenever(id).thenReturn("reply-id") }) + assertThatJsonIsSuccessful() 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() + } + + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.getInstance(), notNullValue()) + } + }