Add more tests for follow Sone page
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / LikePageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.web.pages.LikePage
4 import net.pterodactylus.sone.web.pages.WebPageTest
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 import org.mockito.Mockito.verifyNoMoreInteractions
10
11 /**
12  * Unit test for [LikePage].
13  */
14 class LikePageTest : WebPageTest() {
15
16         private val page = LikePage(template, webInterface)
17
18         override fun getPage() = page
19
20         @Test
21         fun `get request does not redirect`() {
22                 request("", GET)
23                 page.handleRequest(freenetRequest, templateContext)
24         }
25
26         @Test
27         fun `post request with post id likes post and redirects to return page`() {
28                 request("", POST)
29                 addHttpRequestParameter("type", "post")
30                 addHttpRequestParameter("post", "post-id")
31                 addHttpRequestParameter("returnPage", "return.html")
32                 verifyRedirect("return.html") {
33                         verify(currentSone).addLikedPostId("post-id")
34                 }
35         }
36
37         @Test
38         fun `post request with reply id likes post and redirects to return page`() {
39                 request("", POST)
40                 addHttpRequestParameter("type", "reply")
41                 addHttpRequestParameter("reply", "reply-id")
42                 addHttpRequestParameter("returnPage", "return.html")
43                 verifyRedirect("return.html") {
44                         verify(currentSone).addLikedReplyId("reply-id")
45                 }
46         }
47
48         @Test
49         fun `post request with invalid likes redirects to return page`() {
50                 request("", POST)
51                 addHttpRequestParameter("type", "foo")
52                 addHttpRequestParameter("returnPage", "return.html")
53                 verifyRedirect("return.html") {
54                         verifyNoMoreInteractions(currentSone)
55                 }
56         }
57
58 }