|
15 | 15 | */ |
16 | 16 | package io.getstream.feeds.android.client.api.model |
17 | 17 |
|
| 18 | +import io.getstream.feeds.android.client.api.state.query.CommentsSortDataFields |
| 19 | +import io.getstream.feeds.android.client.internal.model.addReply |
18 | 20 | import io.getstream.feeds.android.client.internal.model.removeReaction |
19 | 21 | import io.getstream.feeds.android.client.internal.model.upsertReaction |
20 | 22 | import io.getstream.feeds.android.client.internal.test.TestData.commentData |
21 | 23 | import io.getstream.feeds.android.client.internal.test.TestData.feedsReactionData |
22 | 24 | import io.getstream.feeds.android.client.internal.test.TestData.threadedCommentData |
| 25 | +import java.util.Date |
23 | 26 | import org.junit.Assert.assertEquals |
24 | 27 | import org.junit.Test |
25 | 28 |
|
@@ -124,4 +127,42 @@ internal class ThreadedCommentDataTest { |
124 | 127 | // Then |
125 | 128 | assertEquals(expected, result) |
126 | 129 | } |
| 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 | + } |
127 | 168 | } |
0 commit comments