Replace delete post page with Kotlin version
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / FollowSonePageTest.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.ArgumentMatchers
9 import org.mockito.ArgumentMatchers.any
10 import org.mockito.ArgumentMatchers.anyString
11 import org.mockito.Mockito.never
12 import org.mockito.Mockito.verify
13
14 /**
15  * Unit test for [FollowSonePage].
16  */
17 class FollowSonePageTest : WebPageTest() {
18
19         private val page = FollowSonePage(template, webInterface)
20
21         override fun getPage() = page
22
23         @Test
24         fun `get request does not redirect`() {
25                 request("", GET)
26                 page.handleRequest(freenetRequest, templateContext)
27         }
28
29         @Test
30         fun `a single sone can be followed`() {
31                 request("", POST)
32                 val sone = mock<Sone>()
33                 addSone("sone-id", sone)
34                 addHttpRequestParameter("sone", "sone-id")
35                 addHttpRequestParameter("returnPage", "return.html")
36                 verifyRedirect("return.html") {
37                         verify(core).followSone(currentSone, "sone-id")
38                         verify(core).markSoneKnown(sone)
39                 }
40         }
41
42         @Test
43         fun `multiple sones can be followed`() {
44                 request("", POST)
45                 val firstSone = mock<Sone>()
46                 addSone("sone-id1", firstSone)
47                 val secondSone = mock<Sone>()
48                 addSone("sone-id2", secondSone)
49                 addHttpRequestParameter("sone", "sone-id1,sone-id2")
50                 addHttpRequestParameter("returnPage", "return.html")
51                 verifyRedirect("return.html") {
52                         verify(core).followSone(currentSone, "sone-id1")
53                         verify(core).followSone(currentSone, "sone-id2")
54                         verify(core).markSoneKnown(firstSone)
55                         verify(core).markSoneKnown(secondSone)
56                 }
57         }
58
59         @Test
60         fun `a non-existing sone is not followed`() {
61                 request("", POST)
62                 addHttpRequestParameter("sone", "sone-id")
63                 addHttpRequestParameter("returnPage", "return.html")
64                 verifyRedirect("return.html") {
65                         verify(core, never()).followSone(ArgumentMatchers.eq(currentSone), anyString())
66                         verify(core, never()).markSoneKnown(any<Sone>())
67                 }
68         }
69
70 }