/*
- * Sone - MemoryDatabaseTest.kt - Copyright © 2013–2019 David Roden
+ * Sone - MemoryDatabaseTest.kt - Copyright © 2013–2020 David 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
@Test
fun `stored sone is made available`() {
storeSone()
- assertThat(memoryDatabase.getPost("post1"), isPost("post1", 1000L, "post1", absent()))
- assertThat(memoryDatabase.getPost("post2"), isPost("post2", 2000L, "post2", of(RECIPIENT_ID)))
+ assertThat(memoryDatabase.getPost("post1"), isPost("post1", 1000L, "post1", null))
+ assertThat(memoryDatabase.getPost("post2"), isPost("post2", 2000L, "post2", RECIPIENT_ID))
assertThat(memoryDatabase.getPost("post3"), nullValue())
assertThat(memoryDatabase.getPostReply("reply1"), isPostReply("reply1", "post1", 3000L, "reply1"))
assertThat(memoryDatabase.getPostReply("reply2"), isPostReply("reply2", "post2", 4000L, "reply2"))
verify(configuration.getStringValue("KnownPosts/0/ID"), times(1)).value = null
}
+ @Test
+ @Dirty("the rate limiter should be mocked")
+ fun `setting posts as knows twice in a row only saves the database once`() {
+ prepareConfigurationValues()
+ val post = mock<Post>()
+ whenever(post.id).thenReturn("post-id")
+ memoryDatabase.setPostKnown(post, true)
+ memoryDatabase.setPostKnown(post, true)
+ verify(configuration, times(1)).getStringValue("KnownPosts/1/ID")
+ }
+
+ @Test
+ @Dirty("the rate limiter should be mocked")
+ fun `setting post replies as knows twice in a row only saves the database once`() {
+ prepareConfigurationValues()
+ val postReply = mock<PostReply>()
+ whenever(postReply.id).thenReturn("post-reply-id")
+ memoryDatabase.setPostReplyKnown(postReply, true)
+ memoryDatabase.setPostReplyKnown(postReply, true)
+ verify(configuration, times(1)).getStringValue("KnownReplies/1/ID")
+ }
+
}
private const val SONE_ID = "sone"