Skip to content

Commit be58158

Browse files
kanake10aleksandar-apostolovgpunto
authored
Add unit tests for addReply function (#115)
* unit tests for addReply function * spotless * test append,increment and sorting under one roof * naming fix * typo fix for consistency * more descriptive * Update val expected to result Co-authored-by: Gianmarco <[email protected]> --------- Co-authored-by: Aleksandar Apostolov <[email protected]> Co-authored-by: Gianmarco <[email protected]>
1 parent 659eb8a commit be58158

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

stream-feeds-android-client/src/test/kotlin/io/getstream/feeds/android/client/api/model/ThreadedCommentDataTest.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
*/
1616
package io.getstream.feeds.android.client.api.model
1717

18+
import io.getstream.feeds.android.client.api.state.query.CommentsSortDataFields
19+
import io.getstream.feeds.android.client.internal.model.addReply
1820
import io.getstream.feeds.android.client.internal.model.removeReaction
1921
import io.getstream.feeds.android.client.internal.model.upsertReaction
2022
import io.getstream.feeds.android.client.internal.test.TestData.commentData
2123
import io.getstream.feeds.android.client.internal.test.TestData.feedsReactionData
2224
import io.getstream.feeds.android.client.internal.test.TestData.threadedCommentData
25+
import java.util.Date
2326
import org.junit.Assert.assertEquals
2427
import org.junit.Test
2528

@@ -124,4 +127,42 @@ internal class ThreadedCommentDataTest {
124127
// Then
125128
assertEquals(expected, result)
126129
}
130+
131+
@Test
132+
fun `addReply should append reply, increment replyCount and keep replies sorted by createdAt`() {
133+
// Given
134+
val comparator =
135+
Comparator<CommentsSortDataFields> { a, b -> b.createdAt.compareTo(a.createdAt) }
136+
137+
val originalComment =
138+
threadedCommentData(
139+
id = "original-comment-1",
140+
parentId = "parent-1",
141+
createdAt = Date(1L),
142+
text = "Original text",
143+
)
144+
145+
val newComment =
146+
threadedCommentData(
147+
id = "updated-comment-1",
148+
parentId = "parent-1",
149+
createdAt = Date(2L),
150+
text = "Updated Text",
151+
)
152+
153+
val parent =
154+
threadedCommentData(
155+
id = "parent-1",
156+
text = "Parent comment",
157+
replies = listOf(originalComment),
158+
replyCount = 1,
159+
)
160+
161+
// When
162+
val result = parent.addReply(newComment, comparator)
163+
164+
// Then
165+
assertEquals(2, result.replyCount)
166+
assertEquals(listOf(newComment, originalComment), result.replies)
167+
}
127168
}

0 commit comments

Comments
 (0)