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

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPageTest.kt
new file mode 100644 (file)
index 0000000..1fd1df7
--- /dev/null
@@ -0,0 +1,37 @@
+package net.pterodactylus.sone.web.ajax
+
+import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.test.mock
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [UnlockSoneAjaxPage].
+ */
+class UnlockSoneAjaxPageTest : JsonPageTest("unlockSone.ajax", requiresLogin = false, pageSupplier = ::UnlockSoneAjaxPage) {
+
+       @Test
+       fun `request without sone results in invalid-sone-id`() {
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-sone-id"))
+       }
+
+       @Test
+       fun `request with invalid sone results in invalid-sone-id`() {
+               addRequestParameter("sone", "invalid")
+               assertThat(json.isSuccess, equalTo(false))
+               assertThat(json.error, equalTo("invalid-sone-id"))
+       }
+
+       @Test
+       fun `request with valid sone results in locked sone`() {
+               val sone = mock<Sone>()
+               addLocalSone(sone, "sone-id")
+               addRequestParameter("sone", "sone-id")
+               assertThat(json.isSuccess, equalTo(true))
+               verify(core).unlockSone(sone)
+       }
+
+}