import net.pterodactylus.sone.text.TimeText
import net.pterodactylus.sone.text.TimeTextConverter
import net.pterodactylus.sone.utils.jsonArray
-import net.pterodactylus.sone.web.NewElements
import net.pterodactylus.sone.web.baseInjector
import net.pterodactylus.util.notify.Notification
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyLong
+import org.mockito.ArgumentMatchers.isNull
+import org.mockito.Mockito.verify
import java.util.Locale.ENGLISH
import java.util.TimeZone
}
@Test
- fun `page returns new posts`() {
+ fun `page returns new posts without current Sone`() {
addNewPost("post1", "sone1", 1000)
addNewPost("post2", "sone2", 2000, "sone1")
+ unsetCurrentSone()
assertThat(json.get("newPosts")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
mapOf("id" to "post1", "sone" to "sone1", "time" to "1000", "recipient" to null),
mapOf("id" to "post2", "sone" to "sone2", "time" to "2000", "recipient" to "sone1")
))
+ verify(newElements).newPosts(isNull())
+ }
+
+ @Test
+ fun `page returns new posts with current Sone`() {
+ addNewPost("post1", "sone1", 1000)
+ addNewPost("post2", "sone2", 2000, "sone1")
+ whenever(newElements.newPosts(currentSone)).thenReturn(listOf(newPosts["post2"]!!))
+ assertThat(json.get("newPosts")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
+ mapOf("id" to "post2", "sone" to "sone2", "time" to "2000", "recipient" to "sone1")
+ ))
}
@Test
- fun `page returns new replies`() {
+ fun `page returns new replies without current Sone`() {
addNewReply("reply1", "sone1", "post1", "sone11")
addNewReply("reply2", "sone2", "post2", "sone22")
+ unsetCurrentSone()
assertThat(json.get("newReplies")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
mapOf<String, String?>("id" to "reply1", "sone" to "sone1", "post" to "post1", "postSone" to "sone11"),
mapOf("id" to "reply2", "sone" to "sone2", "post" to "post2", "postSone" to "sone22")
))
+ verify(newElements).newPosts(isNull())
+ }
+
+ @Test
+ fun `page returns new replies with current Sone`() {
+ addNewReply("reply1", "sone1", "post1", "sone11")
+ addNewReply("reply2", "sone2", "post2", "sone22")
+ whenever(newElements.newReplies(currentSone)).thenReturn(listOf(newReplies["reply2"]!!))
+ assertThat(json.get("newReplies")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
+ mapOf("id" to "reply2", "sone" to "sone2", "post" to "post2", "postSone" to "sone22")
+ ))
}
@Test