Add test for like ajax page
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Sep 2017 18:50:40 +0000 (20:50 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Sep 2017 18:50:40 +0000 (20:50 +0200)
src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPageTest.kt
new file mode 100644 (file)
index 0000000..5c90809
--- /dev/null
@@ -0,0 +1,39 @@
+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 [LikeAjaxPage].
+ */
+class LikeAjaxPageTest : JsonPageTest("like.ajax", pageSupplier = ::LikeAjaxPage) {
+
+       @Test
+       fun `request with invalid type results in invalid-type error`() {
+           addRequestParameter("type", "invalid")
+               addRequestParameter("invalid", "invalid-id")
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-type"))
+       }
+
+       @Test
+       fun `request with post id results in post being liked by current sone`() {
+               addRequestParameter("type", "post")
+               addRequestParameter("post", "post-id")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(currentSone).addLikedPostId("post-id")
+               verify(core).touchConfiguration()
+       }
+
+       @Test
+       fun `request with reply id results in reply being liked by current sone`() {
+               addRequestParameter("type", "reply")
+               addRequestParameter("reply", "reply-id")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(currentSone).addLikedReplyId("reply-id")
+               verify(core).touchConfiguration()
+       }
+
+}