test: add unit tests for UserEntity#177
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)
📝 WalkthroughWalkthroughAdded a JUnit 5 test class validating User entity defaults, lifecycle callbacks ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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: 1
🧹 Nitpick comments (1)
src/test/java/org/example/vet1177/entities/UserEntityTest.java (1)
19-20: Use a hash-like fixture value for password tests.Using a plaintext-like literal (
"lösenord!") in apasswordHashflow makes the test intent less clear. Prefer a hash-looking fixture string.Based on learnings: In the `User` entity (`src/main/java/org/example/vet1177/entities/User.java`) the team prefers naming the password field `passwordHash` to clearly signal hashed/encoded storage semantics.Suggested fixture adjustment
- user = new User("Frida Svensson", "Frida@example.se", "lösenord!", Role.OWNER); + user = new User("Frida Svensson", "Frida@example.se", "$2a$10$exampleHashedValue12345678901234567890123456789012", Role.OWNER); ... - assertThat(user.getPassword()).isEqualTo("lösenord!"); + assertThat(user.getPassword()).isEqualTo("$2a$10$exampleHashedValue12345678901234567890123456789012");Also applies to: 95-97
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/vet1177/entities/UserEntityTest.java` around lines 19 - 20, Replace the plaintext password fixture "lösenord!" in the User test with a hash-like fixture string to make intent clear (e.g. "5f4dcc3b5aa765d61d8327deb882cf99") and update any other occurrences (lines noted around 95-97) to use the same hash-looking value; ensure the test constructs User using the password/hash parameter expected by the User class (referencing the User constructor and the passwordHash field) so the test reflects hashed-password semantics.
🤖 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/entities/UserEntityTest.java`:
- Around line 70-76: The test UserEntityTest#onUpdate_shouldRefreshUpdatedAt
only asserts non-null; change it to verify that onUpdate() actually mutates the
timestamp by capturing the previous value (call user.onCreate(); Instant before
= user.getUpdatedAt();) then call user.onUpdate() and assert that
user.getUpdatedAt() is after the captured value (or strictly greater), using the
existing assertion library (e.g., assertThat(...).isAfter(before) or comparable
comparison) so the test fails if updatedAt is not updated.
---
Nitpick comments:
In `@src/test/java/org/example/vet1177/entities/UserEntityTest.java`:
- Around line 19-20: Replace the plaintext password fixture "lösenord!" in the
User test with a hash-like fixture string to make intent clear (e.g.
"5f4dcc3b5aa765d61d8327deb882cf99") and update any other occurrences (lines
noted around 95-97) to use the same hash-looking value; ensure the test
constructs User using the password/hash parameter expected by the User class
(referencing the User constructor and the passwordHash field) so the test
reflects hashed-password semantics.
🪄 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: 1dbeedaf-66df-4c90-8364-138c1903b9f1
📒 Files selected for processing (1)
src/test/java/org/example/vet1177/entities/UserEntityTest.java
Closes #147
Täcker standardvärden, lifecycle callbacks (onCreate, onUpdate), UserDetails-implementationen (getUsername, getPassword, isEnabled, isAccountNonLocked, getAuthorities) samt attachment-hantering (addAttachment, removeAttachment, getUploadedAttachments).
Summary by CodeRabbit