Skip to content

Add response schema stability test for /api/subscriptions - #880

Merged
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
arisu6804:feat/subscriptions-schema-stability-668
Jul 30, 2026
Merged

Add response schema stability test for /api/subscriptions#880
greatest0fallt1me merged 1 commit into
Predictify-org:mainfrom
arisu6804:feat/subscriptions-schema-stability-668

Conversation

@arisu6804

Copy link
Copy Markdown
Contributor

Closes #668

Summary

Added tests/schema/subscriptions.test.ts, a snapshot-based response-shape stability suite for /api/subscriptions, following this repo's existing tests/schema/ convention (e.g. rate-limit.test.ts, alerts.test.ts). Pins the exact JSON returned for:

  • GET / — list shape (secret stripped) and empty-list shape
  • POST / — creation shape (secret included once)
  • POST / — validation-error shape
  • GET /:id — single-resource shape and not-found error shape

Two response fields are non-deterministic per request outside this test's control — the freshly generated secret (a uuidv4() minted per POST /) and correlationId on error responses (a randomUUID() fallback outside requestContextStorage) — both are pinned with expect.any(String) property matchers rather than snapshotted by value, so the suite stays deterministic across runs while still catching shape drift.

This complements the existing behavioral coverage in tests/subscriptions.test.ts (explicit field-by-field assertions for CRUD + validators) rather than duplicating it — the new file's only job is catching accidental shape drift (a renamed/added/removed field) via snapshot diff.

Verification

  • npx jest tests/schema/subscriptions.test.ts — 6/6 pass, run twice back-to-back to confirm the snapshots are stable (second run reports "6 passed" against the committed snapshot file, not "6 written").
  • npx jest tests/subscriptions.test.ts (pre-existing file, unmodified) — 67/68 pass; one pre-existing failure (DELETE /:id expects 204, receives 404) reproduces identically on main (git diff main --stat shows zero modifications to any tracked file in this PR), unrelated to this change.
  • npx tsc --noEmit (project config): only the pre-existing src/routes/users.ts syntax errors present identically on main.
  • npx eslint tests/schema/subscriptions.test.ts — clean, no errors.

Adds snapshot-based tests pinning the exact JSON shape returned by
/api/subscriptions (list, create, fetch-by-id, validation error,
not-found), mirroring the existing tests/schema/ convention (e.g.
rate-limit.test.ts). Complements the behavioral assertions already in
tests/subscriptions.test.ts by catching accidental field
renames/additions/removals as a snapshot diff.

Closes Predictify-org#668
@greatest0fallt1me
greatest0fallt1me merged commit 2884d4b into Predictify-org:main Jul 30, 2026
1 check 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.

Add response schema stability test for /api/subscriptions [b#094]

2 participants