Add unit test for unlike ajax page
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 2 Oct 2017 13:27:58 +0000 (15:27 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 2 Oct 2017 13:27:58 +0000 (15:27 +0200)
src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPageTest.kt [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlikeAjaxPageTest.kt
new file mode 100644 (file)
index 0000000..ada19ba
--- /dev/null
@@ -0,0 +1,58 @@
+package net.pterodactylus.sone.web.ajax
+
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [UnlikeAjaxPage].
+ */
+class UnlikeAjaxPageTest : JsonPageTest("unlike.ajax", pageSupplier = ::UnlikeAjaxPage) {
+
+       @Test
+       fun `request without type results in error`() {
+               assertThat(json.isSuccess, equalTo(false))
+       }
+
+       @Test
+       fun `request for post without id results in invalid-post-id`() {
+               addRequestParameter("type", "post")
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-post-id"))
+       }
+
+       @Test
+       fun `request for invalid type results in invalid-type`() {
+               addRequestParameter("type", "invalid")
+               addRequestParameter("invalid", "invalid")
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-type"))
+       }
+
+       @Test
+       fun `request for post with id removes id from liked posts`() {
+               addRequestParameter("type", "post")
+               addRequestParameter("post", "post-id")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(currentSone).removeLikedPostId("post-id")
+               verify(core).touchConfiguration()
+       }
+
+       @Test
+       fun `request for reply without id results in invalid-reply-id`() {
+               addRequestParameter("type", "reply")
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-reply-id"))
+       }
+
+       @Test
+       fun `request for reply with id removes id from liked replys`() {
+               addRequestParameter("type", "reply")
+               addRequestParameter("reply", "reply-id")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(currentSone).removeLikedReplyId("reply-id")
+               verify(core).touchConfiguration()
+       }
+
+}