Skip to content

Test: add ActivityLogControllerTest with Spring Boot 4 setup#154

Merged
TatjanaTrajkovic merged 1 commit into
mainfrom
test/unit_tests_activity_log_controller
Apr 8, 2026
Merged

Test: add ActivityLogControllerTest with Spring Boot 4 setup#154
TatjanaTrajkovic merged 1 commit into
mainfrom
test/unit_tests_activity_log_controller

Conversation

@TatjanaTrajkovic

@TatjanaTrajkovic TatjanaTrajkovic commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for the activity log retrieval API endpoint. Tests validate that activity logs are correctly filtered and retrieved by medical record ID, and verify the HTTP response contains all required fields: activity description, action type, and the name of the user who performed the action.

@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Introduced a new Spring MVC test class ActivityLogControllerTest that validates the ActivityLogController endpoint for retrieving activity logs by record ID. The test uses MockMvc with mocked services and asserts HTTP 200 response with expected JSON fields.

Changes

Cohort / File(s) Summary
ActivityLogController Test
src/test/java/org/example/vet1177/controller/ActivityLogControllerTest.java
New Spring MVC slice test targeting the activity log retrieval endpoint. Disables authentication filters, mocks ActivityLogService and UserService, and validates JSON response fields (description, action, performedByName) for the GET /api/activity-logs/record/{recordId} endpoint.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • johanbriger
  • annikaholmqvist94
  • lindaeskilsson

Poem

🐰 A test hops forth with mocks so keen,
To verify the logs between,
Status 200, fields aligned—
ActivityLog validation—refined! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new test class for ActivityLogController with Spring Boot MVC test setup.

✏️ 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 test/unit_tests_activity_log_controller

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.

@TatjanaTrajkovic TatjanaTrajkovic linked an issue Apr 7, 2026 that may be closed by this pull request

@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 (1)
src/test/java/org/example/vet1177/controller/ActivityLogControllerTest.java (1)

70-75: Consider asserting response size to make the test stricter.

Right now only element 0 is validated. Adding an array-size assertion will catch accidental extra records in responses.

Proposed tightening
+import static org.hamcrest.Matchers.hasSize;
 import static org.mockito.Mockito.*;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@@
-        mockMvc.perform(get("/api/activity-logs/record/" + recordId)
+        mockMvc.perform(get("/api/activity-logs/record/{recordId}", recordId)
                         .header("userId", userId.toString()))
                 .andExpect(status().isOk())
+                .andExpect(jsonPath("$", hasSize(1)))
                 .andExpect(jsonPath("$[0].description").value("Created case"))
                 .andExpect(jsonPath("$[0].action").value("CASE_CREATED"))
                 .andExpect(jsonPath("$[0].performedByName").value("Alice"));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/java/org/example/vet1177/controller/ActivityLogControllerTest.java`
around lines 70 - 75, The test currently only validates element 0 in the
response from mockMvc.perform(get("/api/activity-logs/record/" + recordId) ...),
so add an explicit array-size assertion (e.g., assert JSON array length == 1
using jsonPath("$.length()").value(1) or jsonPath("$", hasSize(1))) before the
existing element-level assertions to ensure no extra records are returned;
update the ActivityLogControllerTest mockMvc.perform chain to include that size
check prior to the existing jsonPath checks for
description/action/performedByName.
🤖 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/vet1177/controller/ActivityLogControllerTest.java`:
- Around line 70-75: The test currently only validates element 0 in the response
from mockMvc.perform(get("/api/activity-logs/record/" + recordId) ...), so add
an explicit array-size assertion (e.g., assert JSON array length == 1 using
jsonPath("$.length()").value(1) or jsonPath("$", hasSize(1))) before the
existing element-level assertions to ensure no extra records are returned;
update the ActivityLogControllerTest mockMvc.perform chain to include that size
check prior to the existing jsonPath checks for
description/action/performedByName.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99a612fd-0458-4ec1-9ec8-aaa413c7ce6c

📥 Commits

Reviewing files that changed from the base of the PR and between ba13529 and 56c8ee6.

📒 Files selected for processing (1)
  • src/test/java/org/example/vet1177/controller/ActivityLogControllerTest.java

@TatjanaTrajkovic
TatjanaTrajkovic merged commit d22ba54 into main Apr 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: Add Unit tests for ActivityLogController

1 participant