test(app): unit tests for repository layer, crypto/cloudFront utils and session services - #1102
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No linked issues found. Please add the corresponding issues in the pull request description. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Coverage analysis of
packages/appshowed the repository layer was the weakest area by far (35.5% statements), withutilsat 74.77% and parts ofservicesuntested. This PR adds unit tests for those modules; no production code changed.App coverage (statements): 81.3% → 89.45%;
repositories35.5% → 100%;utils74.77% → 86.28%;services82.19% → 85.61%.New tests (16 files) mock Mongoose models with a chainable query stub, so they assert both the returned value and the exact query/aggregation pipeline built:
Covered:
repositories/base CRUD + soft delete, users, images (incl. CloudFront signing/invalidation), keys, request, contactus, rewards, rewardTransactions, milestoneConfig, subscriptions, userSession, usertoken;services/userSession(session id generation, UA parsing, 7-day expiry, 5-session cap) andservices/passwordReset;utils/crypto(AES-256-GCM round trips, tampered tag and wrong-key rejection) andutils/cloudFront.It also fixes a pre-existing leak in 9 existing controller suites (milestones, rewards): they mock
validateSessionwith session objects that have nolastActiveAt, so the auth middleware's fire-and-forgetuserSessionService.touchSession()hit a real, unconnected Mongoose model and logged ausersessions.findOneAndUpdate() buffering timed outerror after teardown. That madejestexit 1 even with every suite passing — i.e. the pre-commit hook failed on a clean checkout. Those suites now stubtouchSession, andpnpm --filter app testexits 0 (88 suites, 772 tests).What type of PR is this? (Check all applicable)
Screenshots (if applicable)
N/A
Checklist
Link to Devin session: https://app.devin.ai/sessions/1cafa20b6a42458f86ca66f8e5b6d3ae
Requested by: @sunnykgupta