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 / BookmarkPageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.util.web.Method.POST
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.junit.Test
9 import org.mockito.ArgumentMatchers.any
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [BookmarkPage].
15  */
16 class BookmarkPageTest: WebPageTest(::BookmarkPage) {
17
18         @Test
19         fun `path is set correctly`() {
20                 assertThat(page.path, equalTo("bookmark.html"))
21         }
22
23         @Test
24         fun `get request does not bookmark anything and does not redirect`() {
25                 verifyNoRedirect {
26                         verify(core, never()).bookmarkPost(any())
27                 }
28         }
29
30         private fun setupBookmarkRequest() {
31                 setMethod(POST)
32                 addHttpRequestPart("returnPage", "return-page.html")
33                 addHttpRequestPart("post", "post-id")
34         }
35
36         @Test
37         fun `post is bookmarked correctly`() {
38                 setupBookmarkRequest()
39                 val post = mock<Post>()
40                 addPost("post-id", post)
41                 verifyRedirect("return-page.html") {
42                         verify(core).bookmarkPost(post)
43                 }
44         }
45
46         @Test
47         fun `non-existing post is not bookmarked`() {
48                 setupBookmarkRequest()
49                 verifyRedirect("return-page.html") {
50                         verify(core, never()).bookmarkPost(any())
51                 }
52         }
53
54 }