Feature/visa tests#32
Conversation
- Added H2 database dependency for in-memory testing. - Configured application-test.properties for the test environment. - Converted selected unit tests to integration tests
- Add JpaConfig for auditing and persistence settings - Add dependency for H2 database - Implement DataInitializer to seed the database with user test data - Implement test suite for VisaViewController
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 45 minutes and 38 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR refactors Spring application startup by extracting JPA auditing and data initialization into dedicated configuration classes, introduces H2 in-memory database for testing with test-specific configuration, converts unit tests to integration tests backed by a real database, expands test coverage with comprehensive controller tests, and corrects a template property reference. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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
🧹 Nitpick comments (1)
src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java (1)
41-43: Remove redundantsave()call.
createAndSaveValidUser()already persists the user (line 156), so the secondsave()at line 43 is unnecessary.♻️ Proposed fix
// Arrange User user = createAndSaveValidUser(); - - user = userRepository.save(user);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java` around lines 41 - 43, The test calls createAndSaveValidUser() which already persists and returns the saved User, so remove the redundant userRepository.save(user) call: keep the User user = createAndSaveValidUser(); assignment and delete the subsequent user = userRepository.save(user); reference createAndSaveValidUser() and userRepository.save(...) to locate and remove the extra persistence step.
🤖 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 157-161: The H2 dependency is currently declared with scope
"runtime" which makes it available in production; update the <dependency> for
com.h2database:h2 in the pom.xml to use scope "test" instead of "runtime" so H2
is only on the test classpath (locate the dependency block containing groupId
com.h2database and artifactId h2 and change its <scope> element to test).
In
`@src/main/java/org/example/visacasemanagementsystem/config/DataInitializer.java`:
- Around line 17-33: Fix the admin email typo and ensure ADMIN creation is
independent of USER existence: change the admin.setEmail("user@test.com2") to a
proper distinct admin address (e.g., "admin@test.com" or similar) and move the
ADMIN creation logic out of the block guarded by
userRepository.findByEmail("user@test.com").isEmpty(); instead, check
userRepository.findByEmail("admin@test.com").isEmpty() (or the chosen admin
email) and create/save the admin user (the User admin object and
admin.setUserAuthorization(UserAuthorization.ADMIN) /
userRepository.save(admin)) in its own conditional so ADMIN is created when
missing regardless of USER presence.
---
Nitpick comments:
In
`@src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java`:
- Around line 41-43: The test calls createAndSaveValidUser() which already
persists and returns the saved User, so remove the redundant
userRepository.save(user) call: keep the User user = createAndSaveValidUser();
assignment and delete the subsequent user = userRepository.save(user); reference
createAndSaveValidUser() and userRepository.save(...) to locate and remove the
extra persistence step.
🪄 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: 890aad37-b8cb-4d1e-9a2b-5ab9e931f156
📒 Files selected for processing (9)
pom.xmlsrc/main/java/org/example/visacasemanagementsystem/VisaCaseManagementSystemApplication.javasrc/main/java/org/example/visacasemanagementsystem/config/DataInitializer.javasrc/main/java/org/example/visacasemanagementsystem/config/JpaConfig.javasrc/main/resources/templates/visa/details.htmlsrc/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.javasrc/test/java/org/example/visacasemanagementsystem/visa/VisaServiceTest.javasrc/test/java/org/example/visacasemanagementsystem/visa/VisaViewControllerTest.javasrc/test/resources/application-test.properties
💤 Files with no reviewable changes (2)
- src/main/java/org/example/visacasemanagementsystem/VisaCaseManagementSystemApplication.java
- src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceTest.java
| if (userRepository.findByEmail("user@test.com").isEmpty()) { | ||
| User user = new User(); | ||
| user.setFullName("USER"); | ||
| user.setEmail("user@test.com"); | ||
| user.setPassword("password"); | ||
| user.setUserAuthorization(UserAuthorization.USER); | ||
| userRepository.save(user); | ||
| System.out.println("Testanvändare skapad med ID: " + user.getId()); | ||
|
|
||
| User admin = new User(); | ||
| admin.setFullName("ADMIN"); | ||
| admin.setEmail("user@test.com2"); | ||
| admin.setPassword("password"); | ||
| admin.setUserAuthorization(UserAuthorization.ADMIN); | ||
| userRepository.save(admin); | ||
| System.out.println("Test-admin skapad med ID: " + admin.getId()); | ||
| } |
There was a problem hiding this comment.
Fix typo in admin email and restructure initialization logic.
Two issues:
- Line 28: Email
"user@test.com2"appears to be a typo—should likely be something like"admin@test.com2"or a distinct admin email. - The ADMIN user creation (lines 26-32) is nested inside the USER check block, so it only runs when the USER doesn't exist. If the USER already exists but the ADMIN doesn't, the ADMIN won't be created.
🔧 Proposed fix
if (userRepository.findByEmail("user@test.com").isEmpty()) {
User user = new User();
user.setFullName("USER");
user.setEmail("user@test.com");
user.setPassword("password");
user.setUserAuthorization(UserAuthorization.USER);
userRepository.save(user);
System.out.println("Testanvändare skapad med ID: " + user.getId());
+ }
+ if (userRepository.findByEmail("admin@test.com2").isEmpty()) {
User admin = new User();
admin.setFullName("ADMIN");
- admin.setEmail("user@test.com2");
+ admin.setEmail("admin@test.com2");
admin.setPassword("password");
admin.setUserAuthorization(UserAuthorization.ADMIN);
userRepository.save(admin);
System.out.println("Test-admin skapad med ID: " + admin.getId());
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (userRepository.findByEmail("user@test.com").isEmpty()) { | |
| User user = new User(); | |
| user.setFullName("USER"); | |
| user.setEmail("user@test.com"); | |
| user.setPassword("password"); | |
| user.setUserAuthorization(UserAuthorization.USER); | |
| userRepository.save(user); | |
| System.out.println("Testanvändare skapad med ID: " + user.getId()); | |
| User admin = new User(); | |
| admin.setFullName("ADMIN"); | |
| admin.setEmail("user@test.com2"); | |
| admin.setPassword("password"); | |
| admin.setUserAuthorization(UserAuthorization.ADMIN); | |
| userRepository.save(admin); | |
| System.out.println("Test-admin skapad med ID: " + admin.getId()); | |
| } | |
| if (userRepository.findByEmail("user@test.com").isEmpty()) { | |
| User user = new User(); | |
| user.setFullName("USER"); | |
| user.setEmail("user@test.com"); | |
| user.setPassword("password"); | |
| user.setUserAuthorization(UserAuthorization.USER); | |
| userRepository.save(user); | |
| System.out.println("Testanvändare skapad med ID: " + user.getId()); | |
| } | |
| if (userRepository.findByEmail("admin@test.com2").isEmpty()) { | |
| User admin = new User(); | |
| admin.setFullName("ADMIN"); | |
| admin.setEmail("admin@test.com2"); | |
| admin.setPassword("password"); | |
| admin.setUserAuthorization(UserAuthorization.ADMIN); | |
| userRepository.save(admin); | |
| System.out.println("Test-admin skapad med ID: " + admin.getId()); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@src/main/java/org/example/visacasemanagementsystem/config/DataInitializer.java`
around lines 17 - 33, Fix the admin email typo and ensure ADMIN creation is
independent of USER existence: change the admin.setEmail("user@test.com2") to a
proper distinct admin address (e.g., "admin@test.com" or similar) and move the
ADMIN creation logic out of the block guarded by
userRepository.findByEmail("user@test.com").isEmpty(); instead, check
userRepository.findByEmail("admin@test.com").isEmpty() (or the chosen admin
email) and create/save the admin user (the User admin object and
admin.setUserAuthorization(UserAuthorization.ADMIN) /
userRepository.save(admin)) in its own conditional so ADMIN is created when
missing regardless of USER presence.
Summary by CodeRabbit
Release Notes