test(usersettings): add integration tests for notification settings route#2804
Conversation
… handler Add integration tests for POST /user/:id/settings/notifications to cover the missing-await bug (regression guard), 200 response body, 404 for unknown users, and 403 for unauthorized access.
|
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)
📝 WalkthroughWalkthroughAdds a new integration test suite for POST Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@server/routes/user/usersettings.test.ts`:
- Around line 56-64: The helper authenticatedAgent mutates the singleton
returned by getSettings() by setting settings.main.localLogin = true and never
restores it, leaking state across tests; modify authenticatedAgent to save the
prior value (e.g., const prev = settings.main.localLogin), set it to true for
the login attempt, and then restore settings.main.localLogin = prev in a finally
block (or equivalent) after the POST to '/auth/local' so the global setting is
always returned to its original value even if the request/assert fails.
🪄 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: f86ffac1-e6b4-4441-ba22-9d375050bb1c
📒 Files selected for processing (1)
server/routes/user/usersettings.test.ts
…okie as insecure
- Restore settings.main.localLogin to its previous value in a finally block
in authenticatedAgent to prevent state leaking between tests
- Explicitly set cookie: { secure: false } on the test session to clarify
that HTTP is intentional in a supertest environment and suppress the
GitHub Advanced Security clear-text-cookie finding
|
Fixed in the latest commit:
|
Description
Adds integration tests for the
POST /user/:id/settings/notificationsroute to provide regression coverage for the unawaiteduserRepository.save()fixed in #2760.Prior to #2760, the handler returned
200before the database write completed. There were no tests asserting the settings were actually persisted to the database, so the race condition went undetected. This suite locks in the expected behavior: changes must be readable from the database after the response returns.AI Disclosure: I used Claude Code to help write the tests. I reviewed and understood all generated code before submitting.
How Has This Been Tested?
New test suite at
server/routes/user/usersettings.test.tsusing the real SQLite test database viasetupTestDb(), following the same pattern asserver/routes/auth.test.ts:persists notification settings to the database-- the core regression guard: re-fetches the user from the DB withrelations: { settings: true }after the POST and asserts the saved values match what was sent. This test would have caught the unawaited save.returns the updated values in the response-- asserts the response body reflects the values that were sent.returns 404 for a non-existent user-- asserts the correct error response for a missing user ID.returns 403 for a non-owner non-admin trying to update another user settings-- asserts the authorization guard is enforced.All 4 tests pass.
Screenshots / Logs (if applicable)
N/A -- test-only change with no runtime behaviour change.
Checklist:
pnpm buildpnpm i18n:extract(no new UI strings added)Summary by CodeRabbit