Skip to content

Add unit tests for CommentDatafetcher and CommentMutation [COG-183]#532

Open
devin-ai-integration[bot] wants to merge 2 commits intochoikh-test-coverage-demofrom
devin/COG-183-1775708877
Open

Add unit tests for CommentDatafetcher and CommentMutation [COG-183]#532
devin-ai-integration[bot] wants to merge 2 commits intochoikh-test-coverage-demofrom
devin/COG-183-1775708877

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot commented Apr 9, 2026

Summary

Adds unit test coverage for the GraphQL comment-related DGS components:

  • CommentDatafetcherTest (8 tests): Covers getComment (local context extraction) and articleComments (forward/backward pagination with first/last, cursor parameters, empty results, anonymous user access, and the first+last null validation).
  • CommentMutationTest (9 tests): Covers createComment (happy path, unauthenticated, article not found, comment data not found after save) and removeComment (deletion by article author, deletion by comment author, unauthenticated, article not found, comment not found, unauthorized user).

Authentication is mocked via SecurityContextHolder with TestingAuthenticationToken / AnonymousAuthenticationToken, cleaned up in @AfterEach. Since DgsDataFetchingEnvironment is a final Kotlin class, the tests mock the underlying DataFetchingEnvironment interface and wrap it via new DgsDataFetchingEnvironment(delegate).

Updates since last revision

  • Fixed should_remove_comment_successfully_by_article_author to use a separate commentAuthor user for the comment, so the test properly isolates the article-author branch of AuthorizationService.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

  • Mocking approach for DgsDataFetchingEnvironment: Tests mock the underlying DataFetchingEnvironment and construct DgsDataFetchingEnvironment around it. This tests method logic but does not verify DGS framework wiring (@DgsData, @InputArgument resolution). Decide if this unit-level coverage is sufficient or if integration tests with DgsQueryExecutor are also needed.
  • Authorization test isolation: Verify that should_remove_comment_successfully_by_article_author and should_remove_comment_successfully_by_comment_author each truly exercise only one branch of AuthorizationService.canWriteComment. The former uses user as article author with a different commentAuthor; the latter uses user as comment author with a different articleAuthor.
  • Run ./gradlew test locally to confirm all 17 new tests pass. Note: spotlessApply requires JDK 17 --add-exports flags due to a pre-existing Google Java Format compatibility issue.

Notes

  • No production code was modified — this is a test-only change.
  • Linked to Linear issue COG-183.

Link to Devin session: https://app.devin.ai/sessions/76151aa74ba4480c81ded3ab5482fa8d
Requested by: @choikh0423


Open with Devin

- 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>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

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>
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.

1 participant