🔀 Merge branch 'release/v82'
[Sone.git] / web / pages / LikePageTest.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.Mockito.verify
8 import org.mockito.Mockito.verifyNoMoreInteractions
9
10 /**
11  * Unit test for [LikePage].
12  */
13 class LikePageTest: WebPageTest(::LikePage) {
14
15         @Test
16         fun `page returns correct path`() {
17             assertThat(page.path, equalTo("like.html"))
18         }
19
20         @Test
21         fun `page requires login`() {
22             assertThat(page.requiresLogin(), equalTo(true))
23         }
24
25         @Test
26         fun `page returns correct title`() {
27             addTranslation("Page.Like.Title", "like page title")
28                 assertThat(page.getPageTitle(freenetRequest), equalTo("like page title"))
29         }
30
31         @Test
32         fun `get request does not redirect`() {
33                 verifyNoRedirect {}
34         }
35
36         @Test
37         fun `post request with post id likes post and redirects to return page`() {
38                 setMethod(POST)
39                 addHttpRequestPart("type", "post")
40                 addHttpRequestPart("post", "post-id")
41                 addHttpRequestPart("returnPage", "return.html")
42                 verifyRedirect("return.html") {
43                         verify(currentSone).addLikedPostId("post-id")
44                 }
45         }
46
47         @Test
48         fun `post request with reply id likes post and redirects to return page`() {
49                 setMethod(POST)
50                 addHttpRequestPart("type", "reply")
51                 addHttpRequestPart("reply", "reply-id")
52                 addHttpRequestPart("returnPage", "return.html")
53                 verifyRedirect("return.html") {
54                         verify(currentSone).addLikedReplyId("reply-id")
55                 }
56         }
57
58         @Test
59         fun `post request with invalid likes redirects to return page`() {
60                 setMethod(POST)
61                 addHttpRequestPart("type", "foo")
62                 addHttpRequestPart("returnPage", "return.html")
63                 verifyRedirect("return.html") {
64                         verifyNoMoreInteractions(currentSone)
65                 }
66         }
67
68 }