X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetNotificationsAjaxPageTest.kt;h=8084b654c4da0df42fc8868f145a50ab0e549d59;hb=aefada2a6f469577c522c54b23d00ee735daa019;hp=d625facd9a3466172c1920899e8268b1d5439bc0;hpb=e194b91c7053152c9c5503f8882e1ddefcd23bdc;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt index d625fac..8084b65 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPageTest.kt @@ -24,7 +24,7 @@ import java.io.Writer */ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requiresLogin = false, needsFormPassword = false, pageSupplier = ::GetNotificationsAjaxPage) { - private val notifications = listOf( + private val testNotifications = listOf( createNotification("n1", 2000, "t1", 5000, true), createNotification("n2", 1000, "t2", 6000, false), createNotification("n3", 3000, "t3", 7000, true) @@ -42,17 +42,17 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi @Test fun `notification hash is calculated correctly`() { - notifications.forEach { addNotification(it) } - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["notificationHash"].asInt(), equalTo(listOf(1, 0, 2).map(notifications::get).hashCode())) + testNotifications.forEach { addNotification(it) } + assertThatJsonIsSuccessful() + assertThat(json["notificationHash"]?.asInt(), equalTo(listOf(1, 0, 2).map(testNotifications::get).hashCode())) } @Test fun `options are included correctly`() { - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["options"]["ShowNotification/NewSones"].asBoolean(), equalTo(true)) - assertThat(json["options"]["ShowNotification/NewPosts"].asBoolean(), equalTo(true)) - assertThat(json["options"]["ShowNotification/NewReplies"].asBoolean(), equalTo(true)) + assertThatJsonIsSuccessful() + assertThat(json["options"]!!["ShowNotification/NewSones"].asBoolean(), equalTo(true)) + assertThat(json["options"]!!["ShowNotification/NewPosts"].asBoolean(), equalTo(true)) + assertThat(json["options"]!!["ShowNotification/NewReplies"].asBoolean(), equalTo(true)) } @Test @@ -60,24 +60,24 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi currentSone.options.isShowNewSoneNotifications = false currentSone.options.isShowNewPostNotifications = false currentSone.options.isShowNewReplyNotifications = false - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["options"]["ShowNotification/NewSones"].asBoolean(), equalTo(false)) - assertThat(json["options"]["ShowNotification/NewPosts"].asBoolean(), equalTo(false)) - assertThat(json["options"]["ShowNotification/NewReplies"].asBoolean(), equalTo(false)) + assertThatJsonIsSuccessful() + assertThat(json["options"]!!["ShowNotification/NewSones"].asBoolean(), equalTo(false)) + assertThat(json["options"]!!["ShowNotification/NewPosts"].asBoolean(), equalTo(false)) + assertThat(json["options"]!!["ShowNotification/NewReplies"].asBoolean(), equalTo(false)) } @Test fun `options are not included if user is not logged in`() { unsetCurrentSone() - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["options"].toList(), empty()) + assertThatJsonIsSuccessful() + assertThat(json["options"]?.toList(), empty()) } @Test fun `notifications are rendered correctly`() { - notifications.forEach { addNotification(it) } - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["notifications"].toList().map { node -> listOf("id", "text", "createdTime", "lastUpdatedTime", "dismissable").map { it to node.get(it).asText() }.toMap() }, containsInAnyOrder( + testNotifications.forEach { addNotification(it) } + assertThatJsonIsSuccessful() + assertThat(json["notifications"]!!.toList().map { node -> listOf("id", "text", "createdTime", "lastUpdatedTime", "dismissable").map { it to node.get(it).asText() }.toMap() }, containsInAnyOrder( mapOf("id" to "n1", "createdTime" to "2000", "lastUpdatedTime" to "5000", "dismissable" to "true", "text" to "t1"), mapOf("id" to "n2", "createdTime" to "1000", "lastUpdatedTime" to "6000", "dismissable" to "false", "text" to "t2"), mapOf("id" to "n3", "createdTime" to "3000", "lastUpdatedTime" to "7000", "dismissable" to "true", "text" to "t3") @@ -97,10 +97,10 @@ class GetNotificationsAjaxPageTest : JsonPageTest("getNotifications.ajax", requi whenever(templateContext).thenReturn(TemplateContext()) whenever(render(any(), any())).then { it.get(1).write("t4") } } - notifications.forEach { addNotification(it) } + testNotifications.forEach { addNotification(it) } addNotification(templateNotification) - assertThat(json.isSuccess, equalTo(true)) - assertThat(json["notifications"].last()["text"].asText(), equalTo("t4")) + assertThatJsonIsSuccessful() + assertThat(json["notifications"]!!.last()["text"].asText(), equalTo("t4")) val templateContext = argumentCaptor() verify(templateNotification).render(templateContext.capture(), any()) assertThat(templateContext.value["core"], equalTo(core))