Add more tests for follow Sone page
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / UnlikePageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.web.pages.UnlikePage
4 import net.pterodactylus.util.web.Method
5 import net.pterodactylus.util.web.Method.POST
6 import org.junit.Test
7 import org.mockito.ArgumentMatchers
8 import org.mockito.ArgumentMatchers.any
9 import org.mockito.Mockito
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [UnlikePage].
15  */
16 class UnlikePageTest : WebPageTest() {
17
18         private val page = UnlikePage(template, webInterface)
19
20         override fun getPage() = page
21
22         @Test
23         fun `get request does not redirect`() {
24                 page.handleRequest(freenetRequest, templateContext)
25         }
26
27         @Test
28         fun `post request does not remove any likes but redirects`() {
29             request("", POST)
30                 addHttpRequestParameter("returnPage", "return.html")
31                 verifyRedirect("return.html") {
32                         verify(currentSone, never()).removeLikedPostId(any())
33                         verify(currentSone, never()).removeLikedReplyId(any())
34                 }
35         }
36
37         @Test
38         fun `post request removes post like and redirects`() {
39             request("", POST)
40                 addHttpRequestParameter("returnPage", "return.html")
41                 addHttpRequestParameter("type", "post")
42                 addHttpRequestParameter("id", "post-id")
43                 verifyRedirect("return.html") {
44                         verify(currentSone, never()).removeLikedPostId("post-id")
45                         verify(currentSone, never()).removeLikedReplyId(any())
46                 }
47         }
48
49         @Test
50         fun `post request removes reply like and redirects`() {
51             request("", POST)
52                 addHttpRequestParameter("returnPage", "return.html")
53                 addHttpRequestParameter("type", "reply")
54                 addHttpRequestParameter("id", "reply-id")
55                 verifyRedirect("return.html") {
56                         verify(currentSone, never()).removeLikedPostId(any())
57                         verify(currentSone, never()).removeLikedReplyId("reply-id")
58                 }
59         }
60
61 }