Add test for unbookmark ajax page
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 2 Oct 2017 12:37:27 +0000 (14:37 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 2 Oct 2017 12:37:27 +0000 (14:37 +0200)
src/test/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPageTest.kt [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPageTest.kt
new file mode 100644 (file)
index 0000000..703b9cd
--- /dev/null
@@ -0,0 +1,47 @@
+package net.pterodactylus.sone.web.ajax
+
+import net.pterodactylus.sone.data.Post
+import net.pterodactylus.sone.test.mock
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+import org.mockito.ArgumentMatchers.any
+import org.mockito.ArgumentMatchers.eq
+import org.mockito.Mockito.never
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [UnbookmarkAjaxPage].
+ */
+class UnbookmarkAjaxPageTest : JsonPageTest("unbookmark.ajax", requiresLogin = false, needsFormPassword = true, pageSupplier = ::UnbookmarkAjaxPage) {
+
+       @Test
+       fun `request without post id results in invalid-post-id`() {
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-post-id"))
+       }
+
+       @Test
+       fun `request with empty post id results in invalid-post-id`() {
+               addRequestParameter("post", "")
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-post-id"))
+       }
+
+       @Test
+       fun `request with invalid post id does not unbookmark anything but succeeds`() {
+               addRequestParameter("post", "invalid")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(core, never()).unbookmarkPost(any())
+       }
+
+       @Test
+       fun `request with valid post id does not unbookmark anything but succeeds`() {
+               val post = mock<Post>()
+               addPost(post, "post-id")
+               addRequestParameter("post", "post-id")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(core).unbookmarkPost(eq(post))
+       }
+
+}