From 21dedb25f4c512799fa35cb60581611bb2c92716 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 2 Oct 2017 14:37:27 +0200 Subject: [PATCH] Add test for unbookmark ajax page --- .../sone/web/ajax/UnbookmarkAjaxPageTest.kt | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPageTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPageTest.kt new file mode 100644 index 0000000..703b9cd --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPageTest.kt @@ -0,0 +1,47 @@ +package net.pterodactylus.sone.web.ajax + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.test.mock +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test +import org.mockito.ArgumentMatchers.any +import org.mockito.ArgumentMatchers.eq +import org.mockito.Mockito.never +import org.mockito.Mockito.verify + +/** + * Unit test for [UnbookmarkAjaxPage]. + */ +class UnbookmarkAjaxPageTest : JsonPageTest("unbookmark.ajax", requiresLogin = false, needsFormPassword = true, pageSupplier = ::UnbookmarkAjaxPage) { + + @Test + fun `request without post id results in invalid-post-id`() { + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-post-id")) + } + + @Test + fun `request with empty post id results in invalid-post-id`() { + addRequestParameter("post", "") + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-post-id")) + } + + @Test + fun `request with invalid post id does not unbookmark anything but succeeds`() { + addRequestParameter("post", "invalid") + assertThat(json.isSuccess, equalTo(true)) + verify(core, never()).unbookmarkPost(any()) + } + + @Test + fun `request with valid post id does not unbookmark anything but succeeds`() { + val post = mock() + addPost(post, "post-id") + addRequestParameter("post", "post-id") + assertThat(json.isSuccess, equalTo(true)) + verify(core).unbookmarkPost(eq(post)) + } + +} -- 2.7.4