Skip to content

Test/goals crud#1925

Merged
Priyanshu-byte-coder merged 1 commit into
Priyanshu-byte-coder:mainfrom
ask-z4ch:test/goals-crud
Jun 3, 2026
Merged

Test/goals crud#1925
Priyanshu-byte-coder merged 1 commit into
Priyanshu-byte-coder:mainfrom
ask-z4ch:test/goals-crud

Conversation

@ask-z4ch
Copy link
Copy Markdown
Contributor

@ask-z4ch ask-z4ch commented Jun 3, 2026

Purpose & Rationale

The Goals API CRUD endpoints (GET/POST on /api/goals and 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.ts with four describe blocks — one per endpoint — importing route handlers directly (GET, POST from @/app/api/goals/route; PATCH, DELETE from @/app/api/goals/[id]/route). The test uses vi.hoisted() mocks matching the goals-patch-integrity.test.ts pattern (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

  1. npx vitest run test/goals-crud.test.ts - 17/17 tests passed
  2. npx vitest run test/goals-* - 84/86 tests passed (2 pre-existing failures in goals-patch-integrity, unrelated)
  3. npm run type-check - passed (0 errors)
  4. 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.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

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

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:testing GSSoC type bonus: tests (+10 pts) labels Jun 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@ask-z4ch
Copy link
Copy Markdown
Contributor Author

ask-z4ch commented Jun 3, 2026

@Priyanshu-byte-coder

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>
@Priyanshu-byte-coder Priyanshu-byte-coder added gssoc:approved GSSoC: PR approved for scoring level:intermediate GSSoC: Intermediate difficulty (35 pts) labels Jun 3, 2026
@Priyanshu-byte-coder Priyanshu-byte-coder added the quality:clean GSSoC: Clean quality multiplier (×1.2) label Jun 3, 2026
@Priyanshu-byte-coder Priyanshu-byte-coder merged commit 4d8f7b6 into Priyanshu-byte-coder:main Jun 3, 2026
4 of 10 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

🎉 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC: PR approved for scoring gssoc26 GSSoC 2026 contribution level:intermediate GSSoC: Intermediate difficulty (35 pts) quality:clean GSSoC: Clean quality multiplier (×1.2) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST] Add unit tests for /api/goals CRUD operations

2 participants