From: David ‘Bombe’ Roden Date: Sat, 21 Jan 2017 15:28:20 +0000 (+0100) Subject: Add unit test for unlike page X-Git-Tag: 0.9.7^2~325 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5bd75f4b4b1de78ab1a4b0d43313a3ddcd7109a1;p=Sone.git Add unit test for unlike page --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/UnlikePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/UnlikePageTest.kt new file mode 100644 index 0000000..3bbd1e4 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/UnlikePageTest.kt @@ -0,0 +1,60 @@ +package net.pterodactylus.sone.web + +import net.pterodactylus.util.web.Method +import net.pterodactylus.util.web.Method.POST +import org.junit.Test +import org.mockito.ArgumentMatchers +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito +import org.mockito.Mockito.never +import org.mockito.Mockito.verify + +/** + * Unit test for [UnlikePage]. + */ +class UnlikePageTest : WebPageTest() { + + private val page = UnlikePage(template, webInterface) + + override fun getPage() = page + + @Test + fun `get request does not redirect`() { + page.handleRequest(freenetRequest, templateContext) + } + + @Test + fun `post request does not remove any likes but redirects`() { + request("", POST) + addHttpRequestParameter("returnPage", "return.html") + verifyRedirect("return.html") { + verify(currentSone, never()).removeLikedPostId(any()) + verify(currentSone, never()).removeLikedReplyId(any()) + } + } + + @Test + fun `post request removes post like and redirects`() { + request("", POST) + addHttpRequestParameter("returnPage", "return.html") + addHttpRequestParameter("type", "post") + addHttpRequestParameter("id", "post-id") + verifyRedirect("return.html") { + verify(currentSone, never()).removeLikedPostId("post-id") + verify(currentSone, never()).removeLikedReplyId(any()) + } + } + + @Test + fun `post request removes reply like and redirects`() { + request("", POST) + addHttpRequestParameter("returnPage", "return.html") + addHttpRequestParameter("type", "reply") + addHttpRequestParameter("id", "reply-id") + verifyRedirect("return.html") { + verify(currentSone, never()).removeLikedPostId(any()) + verify(currentSone, never()).removeLikedReplyId("reply-id") + } + } + +}