Skip to content

feat(user): make use case classes internal and add test configurations#55

Merged
LuftigerLuca merged 2 commits into
mainfrom
feat/test
Jun 17, 2026
Merged

feat(user): make use case classes internal and add test configurations#55
LuftigerLuca merged 2 commits into
mainfrom
feat/test

Conversation

@LuftigerLuca

@LuftigerLuca LuftigerLuca commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor

    • Improved internal module encapsulation and architectural boundaries.
  • Tests

    • Expanded integration test coverage for user management operations and workflows.
    • Added test infrastructure and configuration support.
  • Chores

    • Minor code cleanup and test dependency updates.

@LuftigerLuca LuftigerLuca self-assigned this Jun 16, 2026
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@LuftigerLuca, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 13 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e847f24b-29ea-45d2-bf27-52ad6b9a980b

📥 Commits

Reviewing files that changed from the base of the PR and between 84faf4a and 6c8d7c9.

📒 Files selected for processing (21)
  • application/build.gradle
  • application/src/test/kotlin/com/alleslocker/backend/application/CleanArchitectureTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/config/TestAdapterFactory.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/config/TestGatewayFactory.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/config/TestLogger.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/config/TestPasswordHasher.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/config/TestPresenter.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/config/TestUserGatewayAdapter.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/config/UserTestContext.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/ActivateUserUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/AdminResetPasswordUserUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/ChangeUserRoleUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/CreateUserUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/DeactivateUserUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/EditUserUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/GetUserUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/GetUsersPagedUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/LoginUserUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/RequestUserPasswordChangeUseCaseTest.kt
  • application/src/test/kotlin/com/alleslocker/backend/application/integration/user/ResetPasswordUserUseCaseTest.kt
  • bootstrap/build.gradle
📝 Walkthrough

Walkthrough

Seven user use case implementation classes in the application module are made internal. RequestUserPasswordChangeUseCaseImpl additionally fixes its requestor identification by reading request.requestorId instead of request.userId. A leaked ChangeUserRoleUseCaseImpl import is removed from UserController. The bootstrap module gains H2/spring-boot-test dependencies, a test Spring configuration, and eleven Kotest integration test classes covering all user use cases.

Changes

User Use Case Visibility, Logic Fix, and Integration Tests

Layer / File(s) Summary
Use case internal visibility + requestorId fix + import cleanup
application/.../user/usecase/ActivateUserUseCaseImpl.kt, application/.../user/usecase/AdminResetPasswordUserUseCaseImpl.kt, application/.../user/usecase/ChangeUserRoleUseCaseImpl.kt, application/.../user/usecase/CreateUserUseCaseImpl.kt, application/.../user/usecase/DeactivateUserUseCaseImpl.kt, application/.../user/usecase/GetUsersPagedUseCaseImpl.kt, application/.../user/usecase/RequestUserPasswordChangeUseCaseImpl.kt, application/.../user/usecase/ResetPasswordUserUseCaseImpl.kt, web/.../user/controller/UserController.kt
Seven use case Impl classes gain the internal modifier. RequestUserPasswordChangeUseCaseImpl additionally switches from request.userId to request.requestorId for admin authorization and audit attribution. The leaked ChangeUserRoleUseCaseImpl import is removed from UserController.
Test infrastructure: build config, Spring config, test doubles
bootstrap/build.gradle, bootstrap/src/test/resources/application-test.yml, bootstrap/.../integration/config/TestLogger.kt, bootstrap/.../integration/config/TestPasswordHasher.kt, bootstrap/.../integration/config/TestPresenter.kt, bootstrap/.../integration/config/TestUserIntegrationConfig.kt
Adds H2 and spring-boot-test to Gradle test dependencies, introduces application-test.yml configuring an in-memory H2 datasource with Hibernate create-drop, and adds TestLogger, TestPasswordHasher, TestPresenter, and TestUserIntegrationConfig wiring the full UseCaseFactory/GatewayFactory/AdapterFactory graph for tests.
Integration tests: user lifecycle (activate, deactivate, create, edit, get, paged, role)
bootstrap/.../integration/user/ActivateUserUseCaseTest.kt, bootstrap/.../integration/user/DeactivateUserUseCaseTest.kt, bootstrap/.../integration/user/CreateUserUseCaseTest.kt, bootstrap/.../integration/user/EditUserUseCaseTest.kt, bootstrap/.../integration/user/GetUserUseCaseTest.kt, bootstrap/.../integration/user/GetUsersPagedUseCaseTest.kt, bootstrap/.../integration/user/ChangeUserRoleUseCaseTest.kt
Seven Kotest FreeSpec test classes covering activate, deactivate, create, edit, single-user fetch, paged-user fetch, and role-change use cases. Each validates the success path (including isActive, role, persisted fields, and audit log entries) and all failure paths (BadRequest, Unauthorized, NotFound, AlreadyExists).
Integration tests: login and password use cases
bootstrap/.../integration/user/LoginUserUseCaseTest.kt, bootstrap/.../integration/user/AdminResetPasswordUserUseCaseTest.kt, bootstrap/.../integration/user/ResetPasswordUserUseCaseTest.kt, bootstrap/.../integration/user/RequestUserPasswordChangeUseCaseTest.kt
Four Kotest FreeSpec test classes covering login credential checks, admin-initiated password reset, self-service password reset, and request-password-change flows. Each validates success paths (mustChangePassword flag persistence, password hash verification, audit logs) and all authorization/not-found error paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • AllesLockr/Backend#30: Introduced ResetPasswordUserUseCaseImpl, which this PR changes to internal and adds integration tests for.
  • AllesLockr/Backend#16: Introduced the audit log performedByUserId plumbing that is directly affected by the requestorId vs userId fix in RequestUserPasswordChangeUseCaseImpl.
  • AllesLockr/Backend#40: Introduced and wired RequestUserPasswordChangeUseCaseImpl and other admin user use cases that this PR makes internal and tests.

Suggested reviewers

  • wan0v
  • Leviasm

Poem

🐇 Hop, hop — I sealed the classes tight,
internal now, away from public sight.
The requestorId was mixed up, oh my!
Fixed it right, and let the audit log fly.
Eleven tests now guard the warren gate,
H2 in memory — tests run at great rate!

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 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 two main changes: making use case classes internal and adding test configurations for the user module.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/RequestUserPasswordChangeUseCaseTest.kt (1)

93-94: ⚡ Quick win

Assert audit attribution, not only audit count.

Line 93 only checks auditLogs.size. Add an assertion that the emitted log’s performedByUserId equals adminId to lock in the requestorId regression fix.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/RequestUserPasswordChangeUseCaseTest.kt`
around lines 93 - 94, The test in RequestUserPasswordChangeUseCaseTest currently
only verifies the count of audit logs (size shouldBe 1) but does not validate
the content of the emitted audit log. Add an additional assertion after the size
check to verify that the first audit log entry in testLogger.auditLogs has its
performedByUserId property equal to adminId. This ensures the requestorId
regression fix is properly validated in the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/config/TestPasswordHasher.kt`:
- Around line 7-14: The issue is that MessageDigest is mutable and not
thread-safe; keeping it as a class field (digest) in this Spring singleton
causes nondeterministic hashes when tests run concurrently. Remove the digest
field and instead create a new MessageDigest instance directly inside the hash
method each time it's called using MessageDigest.getInstance("SHA-256"), so that
each invocation gets its own fresh instance rather than sharing the mutable
state across calls in the hash and verify methods.

In
`@bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/config/TestUserIntegrationConfig.kt`:
- Around line 39-42: The testLogger() bean method in
TestUserIntegrationConfig.kt declares a return type of Logger (interface), but
tests inject TestLogger (concrete class) directly, which causes Spring
autowiring failures since the framework does not guarantee concrete class
injection when `@Bean` declares an interface return type. Change the return type
of the testLogger() method from Logger to TestLogger to enable reliable
autowiring by concrete class.

In `@bootstrap/src/test/resources/application-test.yml`:
- Line 19: The master-key property in application-test.yml is hardcoded with a
real-looking cryptographic value, creating security and scanner noise concerns.
Replace the hardcoded key value with a clearly non-production placeholder string
(such as "test-key" or "dev-test-key") that is obviously not suitable for
production. Additionally, ensure the application is configured to support
environment variable overrides for the app.security.master-key property so that
the actual test key can be injected via environment configuration rather than
committed to version control.

---

Nitpick comments:
In
`@bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/RequestUserPasswordChangeUseCaseTest.kt`:
- Around line 93-94: The test in RequestUserPasswordChangeUseCaseTest currently
only verifies the count of audit logs (size shouldBe 1) but does not validate
the content of the emitted audit log. Add an additional assertion after the size
check to verify that the first audit log entry in testLogger.auditLogs has its
performedByUserId property equal to adminId. This ensures the requestorId
regression fix is properly validated in the test.
🪄 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: e0a3a2ac-982c-4273-bf04-4c1d2e33976e

📥 Commits

Reviewing files that changed from the base of the PR and between 9371bde and 84faf4a.

📒 Files selected for processing (26)
  • application/src/main/kotlin/com/alleslocker/backend/application/user/usecase/ActivateUserUseCaseImpl.kt
  • application/src/main/kotlin/com/alleslocker/backend/application/user/usecase/AdminResetPasswordUserUseCaseImpl.kt
  • application/src/main/kotlin/com/alleslocker/backend/application/user/usecase/ChangeUserRoleUseCaseImpl.kt
  • application/src/main/kotlin/com/alleslocker/backend/application/user/usecase/CreateUserUseCaseImpl.kt
  • application/src/main/kotlin/com/alleslocker/backend/application/user/usecase/DeactivateUserUseCaseImpl.kt
  • application/src/main/kotlin/com/alleslocker/backend/application/user/usecase/GetUsersPagedUseCaseImpl.kt
  • application/src/main/kotlin/com/alleslocker/backend/application/user/usecase/RequestUserPasswordChangeUseCaseImpl.kt
  • application/src/main/kotlin/com/alleslocker/backend/application/user/usecase/ResetPasswordUserUseCaseImpl.kt
  • bootstrap/build.gradle
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/config/TestLogger.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/config/TestPasswordHasher.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/config/TestPresenter.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/config/TestUserIntegrationConfig.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/ActivateUserUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/AdminResetPasswordUserUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/ChangeUserRoleUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/CreateUserUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/DeactivateUserUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/EditUserUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/GetUserUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/GetUsersPagedUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/LoginUserUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/RequestUserPasswordChangeUseCaseTest.kt
  • bootstrap/src/test/kotlin/com/alleslocker/backend/bootstrap/integration/user/ResetPasswordUserUseCaseTest.kt
  • bootstrap/src/test/resources/application-test.yml
  • web/src/main/kotlin/com/alleslocker/backend/web/user/controller/UserController.kt
💤 Files with no reviewable changes (1)
  • web/src/main/kotlin/com/alleslocker/backend/web/user/controller/UserController.kt

Comment thread bootstrap/src/test/resources/application-test.yml Outdated
@LuftigerLuca
LuftigerLuca requested review from Leviasm and wan0v June 17, 2026 08:15
@LuftigerLuca
LuftigerLuca merged commit ed1a861 into main Jun 17, 2026
5 checks passed
@LuftigerLuca
LuftigerLuca deleted the feat/test branch June 17, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants