test: add unit tests for UserService#178
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new JUnit 5 test suite Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/test/java/org/example/vet1177/services/UserServiceTest.java`:
- Around line 75-370: Add missing read-path unit tests for
userService.getByEmail, userService.getUserEntityById, userService.getById and
userService.getAllUsers: for getByEmail mock userRepository.findByEmail to
return Optional.of(user) and assert returned UserResponse fields and that
repository was invoked, plus a test where findByEmail returns Optional.empty()
and assert ResourceNotFoundException; for getUserEntityById mock
userRepository.findById to return Optional.of(user) and assert the returned User
entity, plus a test for Optional.empty() -> ResourceNotFoundException; for
getById mock userRepository.findById to return Optional.of(user) and assert
UserResponse mapping and unknown id -> ResourceNotFoundException; for
getAllUsers mock userRepository.findAll (or appropriate paged method) to return
a list of users and assert userService.getAllUsers returns the mapped list and
verify repository interaction. Ensure you use the same naming/style as existing
tests and reuse the existing fixtures (ownerUser/vetUser/userId/clinicId).
- Around line 78-91: The test createUser_owner_withoutClinic_returnsResponse
currently stubs userRepository.save(...) so it can't detect if raw passwords are
persisted; modify the test in UserServiceTest to capture the User passed to
userRepository.save (use an ArgumentCaptor<User> or verify with an argument
matcher) and assert that the saved User.password is not the plain request
password and is encoded by the service (use the
PasswordEncoder.matches(rawPassword, saved.getPassword()) or equivalent) while
keeping the existing assertions on response and verify(userRepository).save(...)
to ensure the password-hashing contract enforced by createUser is validated.
🪄 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: 85ef67d0-5cc4-47fe-afd1-c12c896a3fc0
📒 Files selected for processing (1)
src/test/java/org/example/vet1177/services/UserServiceTest.java
Closes #148
Täcker createUser, getByEmail, getUserEntityById, getById, getAllUsers, updateUser och deleteUser inklusive affärsregler för klinik-koppling, email-validering och blockering av radering vid kopplade resurser.
Summary by CodeRabbit