Add test for DI constructability of TrustAjaxPage
[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 net.pterodactylus.sone.test.getInstance
5 import net.pterodactylus.sone.web.baseInjector
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.hamcrest.Matchers.notNullValue
9 import org.junit.Test
10 import org.mockito.ArgumentMatchers.any
11 import org.mockito.Mockito.never
12 import org.mockito.Mockito.verify
13
14 /**
15  * Unit test for [BookmarkAjaxPage].
16  */
17 class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false, pageSupplier = ::BookmarkAjaxPage) {
18
19         @Test
20         fun `missing post ID results in invalid id response`() {
21                 assertThatJsonFailed("invalid-post-id")
22         }
23
24         @Test
25         fun `empty post ID results in invalid id response`() {
26                 addRequestParameter("post", "")
27                 assertThatJsonFailed("invalid-post-id")
28         }
29
30         @Test
31         fun `invalid post ID results in success but does not bookmark anything`() {
32                 addRequestParameter("post", "missing")
33                 assertThatJsonIsSuccessful()
34                 verify(core, never()).bookmarkPost(any<Post>())
35         }
36
37         @Test
38         fun `valid post ID results in success and bookmarks the post`() {
39                 addRequestParameter("post", "valid-post-id")
40                 val post = addNewPost("valid-post-id", "1", 2)
41                 assertThatJsonIsSuccessful()
42                 verify(core).bookmarkPost(post)
43         }
44
45         @Test
46         fun `page can be created by dependency injection`() {
47             assertThat(baseInjector.getInstance<BookmarkAjaxPage>(), notNullValue())
48         }
49
50 }