test: add CommentController MVC tests and remove insuranceNumber from Pet#130
Conversation
- Removed `insuranceNumber` from `PetRequest`, `PetResponse`, and relevant methods in `PetController` and `PetService`. - Updated logic to align with the simplified data model.
- Added test coverage for endpoints: `create`, `getByRecord`, `update`, `delete`, and `countByRecord`. - Ensured proper exception handling for validation errors, forbidden access, and missing resources. - Updated `pom.xml` to include test dependencies for Spring Security and WebMVC. Closes #115 Closes #98
📝 WalkthroughWalkthroughThis PR removes the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/org/example/vet1177/services/PetService.java (1)
110-114: Prefer reusingapplyPetRequest(...)here.The assignments are correct, but they duplicate the same mapping already centralized in
applyPetRequest(...). Calling the helper fromupdatePet(...)keeps create/update in sync and reduces the chance of this path drifting again the next timePetRequestchanges.♻️ Suggested simplification
- existingPet.setName(request.getName()); - existingPet.setSpecies(request.getSpecies()); - existingPet.setBreed(request.getBreed()); - existingPet.setDateOfBirth(request.getDateOfBirth()); - existingPet.setWeightKg(request.getWeightKg()); + applyPetRequest(existingPet, request);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/example/vet1177/services/PetService.java` around lines 110 - 114, In updatePet(...), replace the repeated field-by-field assignments to existingPet (setName, setSpecies, setBreed, setDateOfBirth, setWeightKg) with a call to the helper applyPetRequest(existingPet, request) so the same mapping logic used during create is reused; locate the updatePet method and invoke applyPetRequest with the existingPet and the incoming PetRequest to keep mappings centralized and avoid duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pom.xml`:
- Around line 56-60: The POM includes a non-existent dependency artifactId
"spring-boot-starter-webmvc-test"; remove that dependency block and rely on the
existing "spring-boot-starter-test" dependency (which already provides MockMvc
and `@WebMvcTest` support) or replace it with the correct official artifact if
needed; locate the dependency with artifactId "spring-boot-starter-webmvc-test"
in the pom and delete it so the build no longer fails.
---
Nitpick comments:
In `@src/main/java/org/example/vet1177/services/PetService.java`:
- Around line 110-114: In updatePet(...), replace the repeated field-by-field
assignments to existingPet (setName, setSpecies, setBreed, setDateOfBirth,
setWeightKg) with a call to the helper applyPetRequest(existingPet, request) so
the same mapping logic used during create is reused; locate the updatePet method
and invoke applyPetRequest with the existingPet and the incoming PetRequest to
keep mappings centralized and avoid duplication.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dd9f7e6c-9d53-440f-95fc-4760d95e6313
📒 Files selected for processing (6)
pom.xmlsrc/main/java/org/example/vet1177/controller/PetController.javasrc/main/java/org/example/vet1177/dto/request/pet/PetRequest.javasrc/main/java/org/example/vet1177/dto/response/pet/PetResponse.javasrc/main/java/org/example/vet1177/services/PetService.javasrc/test/java/org/example/vet1177/controller/CommentControllerTest.java
💤 Files with no reviewable changes (2)
- src/main/java/org/example/vet1177/controller/PetController.java
- src/main/java/org/example/vet1177/dto/request/pet/PetRequest.java
TatjanaTrajkovic
left a comment
There was a problem hiding this comment.
Ser bra ut! Perfekt att det löser buggarna i main. Grymt jobbat Annika!!
Summary
Test coverage
Varje endpoint testas för:
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests