From 592018740929068926a799d0b9398ed4488a8aab Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 27 Sep 2017 19:15:12 +0200 Subject: [PATCH] Add unit test for mark as known ajax page --- .../sone/web/ajax/MarkAsKnownAjaxPageTest.kt | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPageTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPageTest.kt new file mode 100644 index 0000000..b2db4c1 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPageTest.kt @@ -0,0 +1,73 @@ +package net.pterodactylus.sone.web.ajax + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.PostReply +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.any +import org.mockito.Mockito.never +import org.mockito.Mockito.verify + +/** + * Unit test for [MarkAsKnownAjaxPage]. + */ +class MarkAsKnownAjaxPageTest : JsonPageTest("markAsKnown.ajax", requiresLogin = false, pageSupplier = ::MarkAsKnownAjaxPage) { + + @Test + fun `request without type results in invalid-type`() { + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-type")) + } + + @Test + fun `request with unknown sone returns successfully`() { + addRequestParameter("type", "sone") + addRequestParameter("sone", "invalid") + assertThat(json.isSuccess, equalTo(true)) + verify(core, never()).markSoneKnown(any()) + } + + @Test + fun `request with multiple valid sones marks sones as known and returns successfully`() { + addRequestParameter("type", "sone") + addRequestParameter("id", "sone-id1 sone-id2") + val sone1 = mock().apply { whenever(id).thenReturn("sone-id1") } + val sone2 = mock().apply { whenever(id).thenReturn("sone-id2") } + addSone(sone1) + addSone(sone2) + assertThat(json.isSuccess, equalTo(true)) + verify(core).markSoneKnown(sone1) + verify(core).markSoneKnown(sone2) + } + + @Test + fun `request with multiple valid posts marks posts as known and returns successfully`() { + addRequestParameter("type", "post") + addRequestParameter("id", "post1 post2 post 3") + val post1 = mock() + val post2 = mock() + addPost(post1, "post1") + addPost(post2, "post2") + assertThat(json.isSuccess, equalTo(true)) + verify(core).markPostKnown(post1) + verify(core).markPostKnown(post2) + } + + @Test + fun `request with multiple valid replies marks replies as known and returns successfully`() { + addRequestParameter("type", "reply") + addRequestParameter("id", "reply1 reply2 reply3") + val reply1 = mock() + val reply2 = mock() + addReply(reply1, "reply1") + addReply(reply2, "reply2") + assertThat(json.isSuccess, equalTo(true)) + verify(core).markReplyKnown(reply1) + verify(core).markReplyKnown(reply2) + } + +} -- 2.7.4