Skip to content

test: pin the AI usage DTO validation contract - #39

Merged
akash4550 merged 1 commit into
mainfrom
feat/ai-usage-dto-tests
Aug 10, 2026
Merged

test: pin the AI usage DTO validation contract#39
akash4550 merged 1 commit into
mainfrom
feat/ai-usage-dto-tests

Conversation

@akash4550

Copy link
Copy Markdown
Owner

Problem

GetAIUsageSchema is the zod contract the AI usage analytics route (GET /api/v1/analytics/ai-usage) enforces — it accepts only the bounded days query parameter (1–90, integer) and rejects everything else. It had no direct unit coverage, so the contract was unpinned.

Solution

A new deterministic test suite (ai-usage.dto.test.ts, DB-free):

  • accepts empty params (defaults apply), valid days (1 / 7 / 30 / 90), and numeric-string coercion ('30' → 30)
  • rejects days above the 90 max, below 1, non-integer days (incl. NaN)
  • rejects unknown query fields, unknown body fields, and unknown params (no arbitrary filters / injection surface)
  • documents AI_USAGE_DEFAULT_DAYS = 30 and AI_USAGE_MAX_DAYS = 90

Validation results

  • API tests: 58 suites, 402 passed (392 pre-existing + 10 new)
  • Web tests: 29 files, 147 passed
  • npm run typecheck: clean
  • npm run build: clean
  • Diff: 1 file, 83 additions / 0 deletions; zero new dependencies; zero migrations; zero UI/deployment/CI changes; zero production code changed

Risk

LOW. Tests only — no production code touched.

Rollback

Revert the PR (delete the test file). No production impact either way.

Production behavior

Not changed. The DTO, route, and analytics behavior are untouched. Only coverage was added.

GetAIUsageSchema is the zod contract the ai-usage analytics route
enforces (only the bounded days param), but it had no direct test.
New deterministic tests:

- accepts empty params (defaults), valid days 1/7/30/90, numeric-string
  coercion, rejects days > 90 or < 1, non-integer days (incl. NaN),
  unknown query fields, unknown body fields, unknown params
- documents AI_USAGE_DEFAULT_DAYS=30 / AI_USAGE_MAX_DAYS=90

No production code changed.
@netlify

netlify Bot commented Aug 10, 2026

Copy link
Copy Markdown

Deploy Preview for teamsynch-ai canceled.

Name Link
🔨 Latest commit afc7ce6
🔍 Latest deploy log https://app.netlify.com/projects/teamsynch-ai/deploys/6a7a3a5291ab7200075da8f0

@akash4550
akash4550 merged commit 5896fe4 into main Aug 10, 2026
12 checks passed
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.

1 participant