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.test.mock
6 import net.pterodactylus.sone.web.baseInjector
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers.equalTo
9 import org.hamcrest.Matchers.notNullValue
11 import org.mockito.ArgumentMatchers.any
12 import org.mockito.ArgumentMatchers.eq
13 import org.mockito.Mockito.never
14 import org.mockito.Mockito.verify
17 * Unit test for [UnbookmarkAjaxPage].
19 class UnbookmarkAjaxPageTest : JsonPageTest("unbookmark.ajax", requiresLogin = false, needsFormPassword = true, pageSupplier = ::UnbookmarkAjaxPage) {
22 fun `request without post id results in invalid-post-id`() {
23 assertThatJsonFailed("invalid-post-id")
27 fun `request with empty post id results in invalid-post-id`() {
28 addRequestParameter("post", "")
29 assertThatJsonFailed("invalid-post-id")
33 fun `request with invalid post id does not unbookmark anything and fails`() {
34 addRequestParameter("post", "invalid")
35 assertThat(json.isSuccess, equalTo(false))
36 verify(core, never()).unbookmarkPost(any())
40 fun `request with valid post id does not unbookmark anything but succeeds`() {
41 val post = mock<Post>()
42 addPost(post, "post-id")
43 addRequestParameter("post", "post-id")
44 assertThatJsonIsSuccessful()
45 verify(core).unbookmarkPost(eq(post))
49 fun `page can be created by dependency injection`() {
50 assertThat(baseInjector.getInstance<UnbookmarkAjaxPage>(), notNullValue())