From: David ‘Bombe’ Roden Date: Sun, 27 Nov 2016 13:57:36 +0000 (+0100) Subject: Add unit test for like page X-Git-Tag: 0.9.7^2~382 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=840cf080344dcaeb9a91e37aa0e058a4320b42a0;p=Sone.git Add unit test for like page --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/LikePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/LikePageTest.kt new file mode 100644 index 0000000..aafa8fa --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/LikePageTest.kt @@ -0,0 +1,63 @@ +package net.pterodactylus.sone.web + +import net.pterodactylus.util.web.Method.GET +import net.pterodactylus.util.web.Method.POST +import org.junit.Test +import org.mockito.Mockito.verify +import org.mockito.Mockito.verifyNoMoreInteractions + +/** + * Unit test for [LikePage]. + */ +class LikePageTest : WebPageTest() { + + private val page = LikePage(template, webInterface) + + @Test + fun `get request does not redirect`() { + request("", GET) + page.handleRequest(freenetRequest, templateContext) + } + + @Test + fun `post request with post id likes post and redirects to return page`() { + request("", POST) + addHttpRequestParameter("type", "post") + addHttpRequestParameter("post", "post-id") + addHttpRequestParameter("returnPage", "return.html") + expectedException.expect(WebTestUtils.redirectsTo("return.html")) + try { + page.handleRequest(freenetRequest, templateContext) + } finally { + verify(currentSone).addLikedPostId("post-id") + } + } + + @Test + fun `post request with reply id likes post and redirects to return page`() { + request("", POST) + addHttpRequestParameter("type", "reply") + addHttpRequestParameter("reply", "reply-id") + addHttpRequestParameter("returnPage", "return.html") + expectedException.expect(WebTestUtils.redirectsTo("return.html")) + try { + page.handleRequest(freenetRequest, templateContext) + } finally { + verify(currentSone).addLikedReplyId("reply-id") + } + } + + @Test + fun `post request with invalid likes redirects to return page`() { + request("", POST) + addHttpRequestParameter("type", "foo") + addHttpRequestParameter("returnPage", "return.html") + expectedException.expect(WebTestUtils.redirectsTo("return.html")) + try { + page.handleRequest(freenetRequest, templateContext) + } finally { + verifyNoMoreInteractions(currentSone) + } + } + +}