X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fnotification%2FNotificationHandlerModuleTest.kt;h=0a79cfe39f8b9264271ce06b5310166e67518b37;hb=5076d8379e6413189273defd4f01f241b4a6a57e;hp=27f396f25bcea22803eb0657aae505d3a7ce97d8;hpb=79ef6e4644845290d9feb45a06f8588864dd0a83;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt index 27f396f..0a79cfe 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NotificationHandlerModuleTest.kt @@ -1,5 +1,5 @@ /** - * Sone - NotificationHandlerModuleTest.kt - Copyright © 2019 David ‘Bombe’ Roden + * Sone - NotificationHandlerModuleTest.kt - Copyright © 2019–2020 David ‘Bombe’ Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -205,7 +205,7 @@ class NotificationHandlerModuleTest { fun `new-remote-post-reply notification has correct key and template`() { loaders.templates += "/templates/notify/newReplyNotification.html" to "<% replies>".asTemplate() val notification = injector.getInstance>(named("newRemotePostReply")) - val postReplies = listOf(emptyPostReply(), emptyPostReply()) + val postReplies = listOf(createPostReply(), createPostReply()) postReplies.forEach(notification::add) assertThat(notification.render(), equalTo(postReplies.toString())) } @@ -282,7 +282,7 @@ class NotificationHandlerModuleTest { fun `local-reply notification has correct key and template`() { loaders.templates += "/templates/notify/newReplyNotification.html" to "<% replies>".asTemplate() val notification = injector.getInstance>(named("localReply")) - val replies = listOf(emptyPostReply("reply1"), emptyPostReply("reply2")) + val replies = listOf(createPostReply("reply1"), createPostReply("reply2")) replies.forEach(notification::add) assertThat(notification.render(), equalTo(replies.toString())) } @@ -562,4 +562,50 @@ class NotificationHandlerModuleTest { injector.verifySingletonInstance() } + @Test + fun `sone insert notification supplier is created as singleton`() { + injector.verifySingletonInstance() + } + + @Test + fun `sone insert notification template is loaded correctly`() { + loaders.templates += "/templates/notify/soneInsertNotification.html" to "foo".asTemplate() + injector.getInstance() + .invoke(createRemoteSone()) + .render() + .let { assertThat(it, equalTo("foo")) } + } + + @Test + fun `sone notification supplier returns different notifications for different sones`() { + val supplier = injector.getInstance() + listOf(createRemoteSone(), createRemoteSone(), createRemoteSone()) + .map(supplier) + .distinct() + .let { assertThat(it, hasSize(3)) } + } + + @Test + fun `sone notification supplier caches notifications for a sone`() { + val supplier = injector.getInstance() + val sone = createRemoteSone() + listOf(sone, sone, sone) + .map(supplier) + .distinct() + .let { assertThat(it, hasSize(1)) } + } + + @Test + fun `sone notification supplier sets sone in notification template`() { + val supplier = injector.getInstance() + val sone = createRemoteSone() + val templateNotification = supplier(sone) + assertThat(templateNotification["insertSone"], sameInstance(sone)) + } + + @Test + fun `sone insert handler is created as singleton`() { + injector.verifySingletonInstance() + } + }