From 0e49fb05ba0c23c25d51b4c7584e35e2b923061b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 2 Oct 2017 13:39:56 +0200 Subject: [PATCH] Add unit test for trust ajax page --- .../sone/web/ajax/TrustAjaxPageTest.kt | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt new file mode 100644 index 0000000..b62d40b --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt @@ -0,0 +1,40 @@ +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 [TrustAjaxPage]. + */ +class TrustAjaxPageTest : JsonPageTest("trustSone.ajax", requiresLogin = true, needsFormPassword = true, pageSupplier = ::TrustAjaxPage) { + + private val sone = mock() + + @Test + fun `request with invalid sone results in invalid-sone-id`() { + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-sone-id")) + } + + @Test + fun `request with valid sone trust sone`() { + addSone(sone, "sone-id") + addRequestParameter("sone", "sone-id") + assertThat(json.isSuccess, equalTo(true)) + verify(core).trustSone(currentSone, sone) + } + + @Test + fun `request with valid sone returns positive trust value`() { + addSone(sone, "sone-id") + addRequestParameter("sone", "sone-id") + core.preferences.positiveTrust = 31 + assertThat(json.isSuccess, equalTo(true)) + assertThat(json["trustValue"].asInt(), equalTo(31)) + } + +} -- 2.7.4