Don’t send request to node if there are no posts or replies to get the times for
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / UnlikePageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.util.web.Method.POST
4 import org.hamcrest.MatcherAssert.assertThat
5 import org.hamcrest.Matchers.equalTo
6 import org.junit.Test
7 import org.mockito.ArgumentMatchers.any
8 import org.mockito.Mockito.never
9 import org.mockito.Mockito.verify
10
11 /**
12  * Unit test for [UnlikePage].
13  */
14 class UnlikePageTest: WebPageTest(::UnlikePage) {
15
16         @Test
17         fun `page returns correct path`() {
18             assertThat(page.path, equalTo("unlike.html"))
19         }
20
21         @Test
22         fun `page requires login`() {
23             assertThat(page.requiresLogin(), equalTo(true))
24         }
25
26         @Test
27         fun `page returns correct title`() {
28                 addTranslation("Page.Unlike.Title", "unlike page title")
29             assertThat(page.getPageTitle(freenetRequest), equalTo("unlike page title"))
30         }
31
32         @Test
33         fun `get request does not redirect`() {
34                 verifyNoRedirect { }
35         }
36
37         @Test
38         fun `post request does not remove any likes but redirects`() {
39                 setMethod(POST)
40                 addHttpRequestPart("returnPage", "return.html")
41                 verifyRedirect("return.html") {
42                         verify(currentSone, never()).removeLikedPostId(any())
43                         verify(currentSone, never()).removeLikedReplyId(any())
44                 }
45         }
46
47         @Test
48         fun `post request removes post like and redirects`() {
49                 setMethod(POST)
50                 addHttpRequestPart("returnPage", "return.html")
51                 addHttpRequestPart("type", "post")
52                 addHttpRequestPart("post", "post-id")
53                 verifyRedirect("return.html") {
54                         verify(currentSone).removeLikedPostId("post-id")
55                         verify(currentSone, never()).removeLikedReplyId(any())
56                 }
57         }
58
59         @Test
60         fun `post request removes reply like and redirects`() {
61                 setMethod(POST)
62                 addHttpRequestPart("returnPage", "return.html")
63                 addHttpRequestPart("type", "reply")
64                 addHttpRequestPart("reply", "reply-id")
65                 verifyRedirect("return.html") {
66                         verify(currentSone, never()).removeLikedPostId(any())
67                         verify(currentSone).removeLikedReplyId("reply-id")
68                 }
69         }
70
71 }