From: David ‘Bombe’ Roden Date: Mon, 2 Oct 2017 12:37:27 +0000 (+0200) Subject: Add test for unbookmark ajax page X-Git-Tag: 0.9.7^2~42 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=21dedb25f4c512799fa35cb60581611bb2c92716;p=Sone.git Add test for unbookmark ajax page --- 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)) + } + +}