Add some tests and fix names of tests
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / DistrustPageTest.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.GET
6 import net.pterodactylus.util.web.Method.POST
7 import org.junit.Test
8 import org.mockito.Mockito.verify
9
10 /**
11  * Unit test for [DistrustPage].
12  */
13 class DistrustPageTest : WebPageTest() {
14
15         private val page = DistrustPage(template, webInterface)
16
17         override fun getPage() = page
18
19         @Test
20         fun `get request does not redirect`() {
21                 request("", GET)
22                 page.handleRequest(freenetRequest, templateContext)
23         }
24
25         @Test
26         fun `post request with invalid sone redirects to return page`() {
27                 request("", POST)
28                 addHttpRequestParameter("returnPage", "return.html")
29                 verifyRedirect("return.html")
30         }
31
32         @Test
33         fun `post request with valid sone distrusts sone and redirects to return page`() {
34                 request("", POST)
35                 val remoteSone = mock<Sone>()
36                 addSone("remote-sone-id", remoteSone)
37                 addHttpRequestParameter("returnPage", "return.html")
38                 addHttpRequestParameter("sone", "remote-sone-id")
39                 verifyRedirect("return.html") {
40                         verify(core).distrustSone(currentSone, remoteSone)
41                 }
42         }
43
44 }