Add unit test for unlike page
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 21 Jan 2017 15:28:20 +0000 (16:28 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 21 Jan 2017 15:28:20 +0000 (16:28 +0100)
src/test/kotlin/net/pterodactylus/sone/web/UnlikePageTest.kt [new file with mode: 0644]

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 (file)
index 0000000..3bbd1e4
--- /dev/null
@@ -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")
+               }
+       }
+
+}