1 package net.pterodactylus.sone.web.ajax
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
10 import org.mockito.ArgumentMatchers.any
11 import org.mockito.Mockito.never
12 import org.mockito.Mockito.verify
15 * Unit test for [BookmarkAjaxPage].
17 class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false, pageSupplier = ::BookmarkAjaxPage) {
20 fun `missing post ID results in invalid id response`() {
21 assertThatJsonFailed("invalid-post-id")
25 fun `empty post ID results in invalid id response`() {
26 addRequestParameter("post", "")
27 assertThatJsonFailed("invalid-post-id")
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>())
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)
46 fun `page can be created by dependency injection`() {
47 assertThat(baseInjector.getInstance<BookmarkAjaxPage>(), notNullValue())