Add test for follow sone ajax page
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 9 Sep 2017 09:45:11 +0000 (11:45 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 9 Sep 2017 10:38:14 +0000 (12:38 +0200)
src/test/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPageTest.kt [new file with mode: 0644]

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPageTest.kt
new file mode 100644 (file)
index 0000000..1b40f98
--- /dev/null
@@ -0,0 +1,39 @@
+package net.pterodactylus.sone.web.ajax
+
+import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.test.mock
+import net.pterodactylus.sone.test.whenever
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [FollowSoneAjaxPage].
+ */
+class FollowSoneAjaxPageTest : JsonPageTest("followSone.ajax", pageSupplier = ::FollowSoneAjaxPage) {
+
+       @Test
+       fun `request without sone id results in invalid-sone-id`() {
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-sone-id"))
+       }
+
+       @Test
+       fun `request with sone follows sone`() {
+               addSone(mock<Sone>().apply { whenever(id).thenReturn("sone-id") })
+               addRequestParameter("sone", "sone-id")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(core).followSone(currentSone, "sone-id")
+       }
+
+       @Test
+       fun `request with sone makes sone as known`() {
+               val sone = mock<Sone>()
+               addSone(sone, "sone-id")
+               addRequestParameter("sone", "sone-id")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(core).markSoneKnown(sone)
+       }
+
+}