-
Notifications
You must be signed in to change notification settings - Fork 1
unit tests for addReply function #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
PR checklist ❌The following issues were detected:
What we check
|
threadedCommentData(id = "parent-1", replies = listOf(originalComment), replyCount = 1) | ||
val updated = parent.addReply(newComment, comparator) | ||
|
||
// Then: since comparator sorts descending, originalComment should come first |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@Test | ||
fun `addReply should append reply and increment replyCount`() { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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) |
There was a problem hiding this comment.
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
val updated = parent.addReply(newComment, comparator) | |
// When | |
val updated = parent.addReply(newComment, comparator) |
Goal
Add unit tests for the
addReply
function to ensure it correctly appends replies and updates the replyCount, while maintaining the order of repliesImplementation
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