Add unit test for trust page
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 19 Jan 2017 20:09:32 +0000 (21:09 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 19 Jan 2017 20:09:32 +0000 (21:09 +0100)
src/test/kotlin/net/pterodactylus/sone/web/TrustPageTest.kt [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/TrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/TrustPageTest.kt
new file mode 100644 (file)
index 0000000..a29c0c2
--- /dev/null
@@ -0,0 +1,48 @@
+package net.pterodactylus.sone.web
+
+import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.test.mock
+import net.pterodactylus.util.web.Method.POST
+import org.junit.Test
+import org.mockito.ArgumentMatchers.any
+import org.mockito.ArgumentMatchers.eq
+import org.mockito.Mockito.never
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [TrustPage].
+ */
+class TrustPageTest : WebPageTest() {
+
+       private val page = TrustPage(template, webInterface)
+
+       override fun getPage() = page
+
+       @Test
+       fun `get method does not redirect`() {
+               page.handleRequest(freenetRequest, templateContext)
+       }
+
+       @Test
+       fun `post request with missing sone redirects to return page`() {
+               request("", POST)
+               addHttpRequestParameter("returnPage", "return.html")
+               addHttpRequestParameter("sone", "sone-id")
+               verifyRedirect("return.html") {
+                       verify(core, never()).trustSone(eq(currentSone), any())
+               }
+       }
+
+       @Test
+       fun `post request with existing sone trusts the identity and redirects to return page`() {
+               request("", POST)
+               addHttpRequestParameter("returnPage", "return.html")
+               addHttpRequestParameter("sone", "sone-id")
+               val sone = mock<Sone>()
+               addSone("sone-id", sone)
+               verifyRedirect("return.html") {
+                       verify(core).trustSone(eq(currentSone), eq(sone))
+               }
+       }
+
+}