Skip to content

Conversation

kanake10
Copy link
Contributor

Goal

Add unit tests for the addReply function to ensure it correctly appends replies and updates the replyCount, while maintaining the order of replies

Implementation

Created two test cases for the addReply

Testing

Ran unit tests to confirm:

replyCount is correctly incremented.

The replies list contains the new reply.

Replies are sorted correctly according to the comparator.

Checklist

  • Issue linked (if any)
  • Tests/docs updated
  • I have signed the Stream CLA (required for external contributors)

Copy link
Contributor

github-actions bot commented Oct 15, 2025

PR checklist ❌

The following issues were detected:

  • Missing required label: at least one label starting with pr:.

What we check

  1. Title is concise (5–18 words) unless labeled pr:ignore-for-release.
  2. At least one pr: label exists (e.g., pr:bug, pr:new-feature).
  3. Sections ### Goal, ### Implementation, and ### Testing contain content.

threadedCommentData(id = "parent-1", replies = listOf(originalComment), replyCount = 1)
val updated = parent.addReply(newComment, comparator)

// Then: since comparator sorts descending, originalComment should come first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't specifying createdAt for either originalComment or newComment, so we're not really testing the sorting here, right?

Copy link
Contributor Author

@kanake10 kanake10 Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated this, sorting,append and increment are tested together under one roof

Comment on lines 130 to 131
@Test
fun `addReply should append reply and increment replyCount`() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this test? The behavior it's testing is already covered by the test below.

// Given
val comparator =
Comparator<CommentsSortDataFields> { a, b ->
// Reverse sort for demonstration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Reverse sort for demonstration
// Reverse sort for demonstration

val newComment = threadedCommentData(id = "comment-2", parentId = "parent-1")
val parent =
threadedCommentData(id = "parent-1", replies = listOf(originalComment), replyCount = 1)
val updated = parent.addReply(newComment, comparator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with other tests in this file

Suggested change
val updated = parent.addReply(newComment, comparator)
// When
val updated = parent.addReply(newComment, comparator)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants