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