Test/goals crud#1925
Conversation
|
@ask-z4ch is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
|
During local testing I found a related pre-existing failure in test/goals-patch-integrity.test.ts - 2 tests assert body.error.toMatch(/non-negative integer/) but the PATCH route at src/app/api/goals/[id]/route.ts returns "Invalid current value", so the tests expect 400 but get 200. This affects the same goals PATCH endpoint covered here. Additionally, 4 other pre-existing failures exist in test/dateUtils.test.ts (1), test/discord.test.ts (6), test/github-accounts-api.test.ts (1), and test/local-coding-stats.test.ts (1) - all unrelated. Commas regarding the rest are a separate matter; I'm happy to open a tracking issue if that's helpful. |
Closes Priyanshu-byte-coder#1907 Signed-off-by: Abhisumat Kashyap <abhisumatkashyap@gmail.com>
4d8f7b6
into
Priyanshu-byte-coder:main
|
🎉 Merged! Thanks for contributing to DevTrack. If the project has been useful to you, a ⭐ star on the repo is the easiest way to support it — it helps DevTrack get discovered by more developers. Keep an eye on open issues for your next contribution! |
Purpose & Rationale
The Goals API CRUD endpoints (GET/POST on
/api/goalsand PATCH/DELETE on/api/goals/[id]) had no unit or integration tests, despite past data-loss bugs caused by goal creation and deletion issues. This change adds a dedicated test file covering all four endpoints with auth guard validation and edge cases, following the existing mock patterns used in the repository.Technical Resolution Details
Created
test/goals-crud.test.tswith fourdescribeblocks — one per endpoint — importing route handlers directly (GET,POSTfrom@/app/api/goals/route;PATCH,DELETEfrom@/app/api/goals/[id]/route). The test usesvi.hoisted()mocks matching thegoals-patch-integrity.test.tspattern (session, user resolution, Supabase chain, webhooks). Each endpoint has at least 3 test cases: authentication guard (unauthenticated → 401), happy-path CRUD flow, and endpoint-specific error states (missing fields, non-existent goals, database failures, user-not-found). Closes #1907.Local Testing Execution
npx vitest run test/goals-crud.test.ts- 17/17 tests passednpx vitest run test/goals-*- 84/86 tests passed (2 pre-existing failures ingoals-patch-integrity, unrelated)npm run type-check- passed (0 errors)npm run lint- passed (3 pre-existing warnings, unrelated)Desired Review Feedback Type
Completeness and correctness of mock chain setup for each endpoint, especially whether the sequential Supabase calls in POST (count check then insert) and the two-branch PATCH path (select existing then update) are properly covered.
Integrity & AI Usage Disclosure
In compliance with the GSSoC 2026 AI Conduct rules, I disclose that AI tools were used solely as learning and boilerplate aids. The final logic was fully reviewed, tested, and manually adapted to match human styling and clean-code design.