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

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/UnfollowSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/UnfollowSonePageTest.kt
new file mode 100644 (file)
index 0000000..b9c3433
--- /dev/null
@@ -0,0 +1,42 @@
+package net.pterodactylus.sone.web
+
+import net.pterodactylus.util.web.Method.POST
+import org.junit.Test
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [UnfollowSonePage].
+ */
+class UnfollowSonePageTest : WebPageTest() {
+
+       private val page = UnfollowSonePage(template, webInterface)
+
+       override fun getPage() = page
+
+       @Test
+       fun `get request does not redirect`() {
+               page.handleRequest(freenetRequest, templateContext)
+       }
+
+       @Test
+       fun `post request unfollows a single sone and redirects to return page`() {
+               request("", POST)
+               addHttpRequestParameter("returnPage", "return.html")
+               addHttpRequestParameter("sone", "sone-id")
+               verifyRedirect("return.html") {
+                       verify(core).unfollowSone(currentSone, "sone-id")
+               }
+       }
+
+       @Test
+       fun `post request unfollows two sones and redirects to return page`() {
+               request("", POST)
+               addHttpRequestParameter("returnPage", "return.html")
+               addHttpRequestParameter("sone", "sone-id1, sone-id2")
+               verifyRedirect("return.html") {
+                       verify(core).unfollowSone(currentSone, "sone-id1")
+                       verify(core).unfollowSone(currentSone, "sone-id2")
+               }
+       }
+
+}