1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import org.hamcrest.MatcherAssert.*
7 import org.hamcrest.Matchers.*
9 import org.mockito.ArgumentMatchers.any
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
14 * Unit test for [BookmarkAjaxPage].
16 class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false, pageSupplier = ::BookmarkAjaxPage) {
19 fun `missing post ID results in invalid id response`() {
20 assertThatJsonFailed("invalid-post-id")
24 fun `empty post ID results in invalid id response`() {
25 addRequestParameter("post", "")
26 assertThatJsonFailed("invalid-post-id")
30 fun `invalid post ID results in success but does not bookmark anything`() {
31 addRequestParameter("post", "missing")
32 assertThatJsonIsSuccessful()
33 verify(core, never()).bookmarkPost(any<Post>())
37 fun `valid post ID results in success and bookmarks the post`() {
38 addRequestParameter("post", "valid-post-id")
39 val post = addNewPost("valid-post-id", "1", 2)
40 assertThatJsonIsSuccessful()
41 verify(core).bookmarkPost(post)
45 fun `page can be created by dependency injection`() {
46 assertThat(baseInjector.getInstance<BookmarkAjaxPage>(), notNullValue())