Add unit tests for CommentDatafetcher and CommentMutation [COG-183]#532
Open
devin-ai-integration[bot] wants to merge 2 commits intochoikh-test-coverage-demofrom
Open
Add unit tests for CommentDatafetcher and CommentMutation [COG-183]#532devin-ai-integration[bot] wants to merge 2 commits intochoikh-test-coverage-demofrom
devin-ai-integration[bot] wants to merge 2 commits intochoikh-test-coverage-demofrom
Conversation
- Add CommentDatafetcherTest with 8 tests covering getComment and articleComments methods - Add CommentMutationTest with 9 tests covering createComment and removeComment methods - Tests cover happy paths, error cases, auth checks, and edge cases COG-183 Co-Authored-By: Kyu Choi <kyuhwanchoi0423@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Use a separate commentAuthor user in should_remove_comment_successfully_by_article_author so the test actually exercises the article-author branch of canWriteComment, not the comment-author branch. Addresses Devin Review feedback. Co-Authored-By: Kyu Choi <kyuhwanchoi0423@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds unit test coverage for the GraphQL comment-related DGS components:
CommentDatafetcherTest(8 tests): CoversgetComment(local context extraction) andarticleComments(forward/backward pagination withfirst/last, cursor parameters, empty results, anonymous user access, and thefirst+lastnull validation).CommentMutationTest(9 tests): CoverscreateComment(happy path, unauthenticated, article not found, comment data not found after save) andremoveComment(deletion by article author, deletion by comment author, unauthenticated, article not found, comment not found, unauthorized user).Authentication is mocked via
SecurityContextHolderwithTestingAuthenticationToken/AnonymousAuthenticationToken, cleaned up in@AfterEach. SinceDgsDataFetchingEnvironmentis a final Kotlin class, the tests mock the underlyingDataFetchingEnvironmentinterface and wrap it vianew DgsDataFetchingEnvironment(delegate).Updates since last revision
should_remove_comment_successfully_by_article_authorto use a separatecommentAuthoruser for the comment, so the test properly isolates the article-author branch ofAuthorizationService.canWriteComment(previously both the article and comment were authored by the same user, so both auth branches would pass). Addresses Devin Review feedback.Review & Testing Checklist for Human
DataFetchingEnvironmentand constructDgsDataFetchingEnvironmentaround it. This tests method logic but does not verify DGS framework wiring (@DgsData,@InputArgumentresolution). Decide if this unit-level coverage is sufficient or if integration tests withDgsQueryExecutorare also needed.should_remove_comment_successfully_by_article_authorandshould_remove_comment_successfully_by_comment_authoreach truly exercise only one branch ofAuthorizationService.canWriteComment. The former usesuseras article author with a differentcommentAuthor; the latter usesuseras comment author with a differentarticleAuthor../gradlew testlocally to confirm all 17 new tests pass. Note:spotlessApplyrequires JDK 17--add-exportsflags due to a pre-existing Google Java Format compatibility issue.Notes
Link to Devin session: https://app.devin.ai/sessions/76151aa74ba4480c81ded3ab5482fa8d
Requested by: @choikh0423