From: David ‘Bombe’ Roden Date: Mon, 2 Oct 2017 14:09:23 +0000 (+0200) Subject: Add unit test for untrust ajax page X-Git-Tag: 0.9.7^2~32 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a974622677b4f2f7114fe09e4b3d9eb6cdfd8f20;p=Sone.git Add unit test for untrust ajax page --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPageTest.kt new file mode 100644 index 0000000..cc0193b --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPageTest.kt @@ -0,0 +1,47 @@ +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.hamcrest.Matchers.nullValue +import org.junit.Test +import org.mockito.Mockito.verify + +/** + * Unit test for [UntrustAjaxPage]. + */ +class UntrustAjaxPageTest : JsonPageTest("untrustSone.ajax", pageSupplier = ::UntrustAjaxPage) { + + @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 sone being untrusted`() { + val sone = mock() + addSone(sone, "sone-id") + addRequestParameter("sone", "sone-id") + assertThat(json.isSuccess, equalTo(true)) + verify(core).untrustSone(currentSone, sone) + } + + @Test + fun `request with valid sone results in null trust value being returned`() { + val sone = mock() + addSone(sone, "sone-id") + addRequestParameter("sone", "sone-id") + assertThat(json.isSuccess, equalTo(true)) + assertThat(json["trustValue"], nullValue()) + } + +}