1d26c71dff5033982b45bb55d056fbd77c8f6d1b
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / ajax / BookmarkAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.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 [BookmarkAjaxPage].
13  */
14 class BookmarkAjaxPageTest : JsonPageTest(::BookmarkAjaxPage) {
15
16         @Test
17         fun `page returns correct path`() {
18                 assertThat(page.path, equalTo("bookmark.ajax"))
19         }
20
21         @Test
22         fun `page does not require login`() {
23             assertThat(page.requiresLogin(), equalTo(false))
24         }
25
26         @Test
27         fun `missing post ID results in invalid id response`() {
28                 assertThat(json.isSuccess, equalTo(false))
29                 assertThat((json as JsonErrorReturnObject).error, equalTo("invalid-post-id"))
30         }
31
32         @Test
33         fun `empty post ID results in invalid id response`() {
34                 addRequestParameter("post", "")
35                 assertThat(json.isSuccess, equalTo(false))
36                 assertThat((json as JsonErrorReturnObject).error, equalTo("invalid-post-id"))
37         }
38
39         @Test
40         fun `invalid post ID results in success but does not bookmark anything`() {
41                 addRequestParameter("post", "missing")
42                 assertThat(json.isSuccess, equalTo(true))
43                 verify(core, never()).bookmarkPost(any<Post>())
44         }
45
46         @Test
47         fun `valid post ID results in success and bookmarks the post`() {
48                 addRequestParameter("post", "valid-post-id")
49                 val post = addNewPost("valid-post-id", "1", 2)
50                 assertThat(json.isSuccess, equalTo(true))
51                 verify(core).bookmarkPost(post)
52         }
53
54 }