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