From e4969210bb1c68af8dc434478440516a81d91c6d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 9 Sep 2017 11:45:11 +0200 Subject: [PATCH] Add test for follow sone ajax page --- .../sone/web/ajax/FollowSoneAjaxPageTest.kt | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPageTest.kt 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 index 0000000..1b40f98 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPageTest.kt @@ -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().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() + addSone(sone, "sone-id") + addRequestParameter("sone", "sone-id") + assertThat(json.isSuccess, equalTo(true)) + verify(core).markSoneKnown(sone) + } + +} -- 2.7.4