Skip to content

Add TicketCommentService test suite - #35

Merged
simonforsberg merged 23 commits into
mainfrom
feature/ticketcommentservice-test
Apr 21, 2026
Merged

Add TicketCommentService test suite#35
simonforsberg merged 23 commits into
mainfrom
feature/ticketcommentservice-test

Conversation

@simonforsberg

@simonforsberg simonforsberg commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for ticket comment functionality, including authorization checks, role-based permissions, and error handling validation.

@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a comprehensive JUnit 5 test suite for TicketCommentService covering addComment and getComments methods. Tests validate role-based authorization, comment type permissions, token-based anonymous access, repository interactions, and error handling across various user scenarios.

Changes

Cohort / File(s) Summary
TicketCommentService Test Suite
src/test/java/org/example/alfs/services/TicketCommentServiceTest.java
New test class with nested test groups for addComment and getComments. Tests authorization logic across user roles (ADMIN, INVESTIGATOR, REPORTER, anonymous), validates forbidden/not-found scenarios, verifies repository save behavior, and confirms mapping of comment DTOs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • addee1
  • FionaSprinkles

Poem

🐰 In tests we hop from mock to mock,
Role-based auth, a sturdy rock,
Forbidden paths and tokens right,
Assertions dance from left to right,
Whiskers twitch—the coverage's tight! 🧪✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and accurately describes the main change: adding a comprehensive test suite for the TicketCommentService class.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ticketcommentservice-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/test/java/org/example/alfs/services/TicketCommentServiceTest.java (2)

291-305: Minor: missing save never-called verification.

Unlike the other forbidden-path tests (e.g., lines 288, 271, 237), this one omits verify(ticketCommentRepository, never()).save(any());. Adding it keeps the forbidden-case assertions consistent.

♻️ Suggested addition
             assertEquals(HttpStatus.FORBIDDEN, ex.getStatusCode());
+            verify(ticketCommentRepository, never()).save(any());
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/org/example/alfs/services/TicketCommentServiceTest.java` around
lines 291 - 305, Add a verification that ticketCommentRepository.save is never
called in the anonymous_withNoToken_shouldThrowForbidden test: after asserting
the ResponseStatusException and its FORBIDDEN status, call
verify(ticketCommentRepository, never()).save(any()) to match the other
forbidden-path tests and ensure no save was attempted by
ticketCommentService.addComment when ticketRepository.findById(1L) returns the
anonymous ticket.

119-124: Nit: misplaced // Act / // Assert comments.

In these three tests the when(...) stubbing lines are under // Act while the actual service call is under // Assert. Swap them to // Arrange and // Act + Assert to match the other tests' Arrange-Act-Assert structure.

Also applies to: 137-142, 155-160

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/org/example/alfs/services/TicketCommentServiceTest.java` around
lines 119 - 124, Rename the misplaced comments: change the "// Act" comment that
currently precedes the stubbing lines (when(ticketRepository.findById(1L)),
when(ticketCommentRepository.save(...)),
when(ticketCommentMapper.entityToViewDTO(...))) to "// Arrange", and change the
comment that currently labels the service invocation (the call that follows
these stubs and is currently under "// Assert") to "// Act + Assert" so the test
follows Arrange → Act(+Assert). Apply the same change pattern to the other two
similar blocks that contain the same stubbing + service invocation sequence.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/test/java/org/example/alfs/services/TicketCommentServiceTest.java`:
- Around line 291-305: Add a verification that ticketCommentRepository.save is
never called in the anonymous_withNoToken_shouldThrowForbidden test: after
asserting the ResponseStatusException and its FORBIDDEN status, call
verify(ticketCommentRepository, never()).save(any()) to match the other
forbidden-path tests and ensure no save was attempted by
ticketCommentService.addComment when ticketRepository.findById(1L) returns the
anonymous ticket.
- Around line 119-124: Rename the misplaced comments: change the "// Act"
comment that currently precedes the stubbing lines
(when(ticketRepository.findById(1L)), when(ticketCommentRepository.save(...)),
when(ticketCommentMapper.entityToViewDTO(...))) to "// Arrange", and change the
comment that currently labels the service invocation (the call that follows
these stubs and is currently under "// Assert") to "// Act + Assert" so the test
follows Arrange → Act(+Assert). Apply the same change pattern to the other two
similar blocks that contain the same stubbing + service invocation sequence.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 447bec76-df1d-4c44-9b95-9722187404ef

📥 Commits

Reviewing files that changed from the base of the PR and between 735bdb2 and 3763541.

📒 Files selected for processing (1)
  • src/test/java/org/example/alfs/services/TicketCommentServiceTest.java

@simonforsberg simonforsberg changed the title Add TicketCommentService test suite Add TicketCommentService test suite Apr 21, 2026
@simonforsberg
simonforsberg merged commit 37de63d into main Apr 21, 2026
2 checks passed
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