1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.data.Post
4 import org.hamcrest.MatcherAssert.assertThat
5 import org.hamcrest.Matchers.equalTo
7 import org.mockito.ArgumentMatchers.any
8 import org.mockito.Mockito.never
9 import org.mockito.Mockito.verify
12 * Unit test for [BookmarkAjaxPage].
14 class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false, pageSupplier = ::BookmarkAjaxPage) {
17 fun `missing post ID results in invalid id response`() {
18 assertThat(json.isSuccess, equalTo(false))
19 assertThat(json.error, equalTo("invalid-post-id"))
23 fun `empty post ID results in invalid id response`() {
24 addRequestParameter("post", "")
25 assertThat(json.isSuccess, equalTo(false))
26 assertThat(json.error, equalTo("invalid-post-id"))
30 fun `invalid post ID results in success but does not bookmark anything`() {
31 addRequestParameter("post", "missing")
32 assertThat(json.isSuccess, equalTo(true))
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 assertThat(json.isSuccess, equalTo(true))
41 verify(core).bookmarkPost(post)