Replace delete post page with Kotlin version
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / TrustPageTest.kt
1 package net.pterodactylus.sone.web
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.util.web.Method.POST
6 import org.junit.Test
7 import org.mockito.ArgumentMatchers.any
8 import org.mockito.ArgumentMatchers.eq
9 import org.mockito.Mockito.never
10 import org.mockito.Mockito.verify
11
12 /**
13  * Unit test for [TrustPage].
14  */
15 class TrustPageTest : WebPageTest() {
16
17         private val page = TrustPage(template, webInterface)
18
19         override fun getPage() = page
20
21         @Test
22         fun `get method does not redirect`() {
23                 page.handleRequest(freenetRequest, templateContext)
24         }
25
26         @Test
27         fun `post request with missing sone redirects to return page`() {
28                 request("", POST)
29                 addHttpRequestParameter("returnPage", "return.html")
30                 addHttpRequestParameter("sone", "sone-id")
31                 verifyRedirect("return.html") {
32                         verify(core, never()).trustSone(eq(currentSone), any())
33                 }
34         }
35
36         @Test
37         fun `post request with existing sone trusts the identity and redirects to return page`() {
38                 request("", POST)
39                 addHttpRequestParameter("returnPage", "return.html")
40                 addHttpRequestParameter("sone", "sone-id")
41                 val sone = mock<Sone>()
42                 addSone("sone-id", sone)
43                 verifyRedirect("return.html") {
44                         verify(core).trustSone(eq(currentSone), eq(sone))
45                 }
46         }
47
48 }