From 4ef415ab45a6c4c7410b0a0f9c3f393ffad53da9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Sep 2017 19:55:47 +0200 Subject: [PATCH] Add test for get reply ajax page --- .../sone/web/ajax/GetReplyAjaxPageTest.kt | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPageTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPageTest.kt new file mode 100644 index 0000000..8fe16e2 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetReplyAjaxPageTest.kt @@ -0,0 +1,53 @@ +package net.pterodactylus.sone.web.ajax + +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 net.pterodactylus.sone.utils.asTemplate +import net.pterodactylus.util.template.ReflectionAccessor +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test + +/** + * Unit test for [GetReplyAjaxPage]. + */ +class GetReplyAjaxPageTest : JsonPageTest("getReply.ajax", needsFormPassword = false, + pageSupplier = { webInterface -> + GetReplyAjaxPage(webInterface, "<%core>\n<%request>\n<%reply.text>\n<%currentSone>".asTemplate()) + }) { + + @Test + fun `request without reply id results in invalid-reply-id`() { + assertThat(json.isSuccess, equalTo(false)) + assertThat(json.error, equalTo("invalid-reply-id")) + } + + @Test + fun `request with valid reply id results in reply json`() { + val sone = mock().apply { whenever(id).thenReturn("sone-id") } + val reply = mock().apply { + whenever(id).thenReturn("reply-id") + whenever(this.sone).thenReturn(sone) + whenever(postId).thenReturn("post-id") + whenever(time).thenReturn(1000) + whenever(text).thenReturn("reply text") + } + webInterface.templateContextFactory.addAccessor(Any::class.java, ReflectionAccessor()) + addReply(reply) + addRequestParameter("reply", "reply-id") + assertThat(json.isSuccess, equalTo(true)) + assertThat(json["reply"]["id"].asText(), equalTo("reply-id")) + assertThat(json["reply"]["soneId"].asText(), equalTo("sone-id")) + assertThat(json["reply"]["postId"].asText(), equalTo("post-id")) + assertThat(json["reply"]["time"].asLong(), equalTo(1000L)) + assertThat(json["reply"]["html"].asText(), equalTo(listOf( + core.toString(), + freenetRequest.toString(), + "reply text", + currentSone.toString() + ).joinToString("\n"))) + } + +} -- 2.7.4