Add response schema stability test for /api/subscriptions - #880
Merged
greatest0fallt1me merged 1 commit intoJul 30, 2026
Merged
Conversation
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
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.
Closes #668
Summary
Added
tests/schema/subscriptions.test.ts, a snapshot-based response-shape stability suite for/api/subscriptions, following this repo's existingtests/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 shapePOST /— creation shape (secret included once)POST /— validation-error shapeGET /:id— single-resource shape and not-found error shapeTwo response fields are non-deterministic per request outside this test's control — the freshly generated
secret(auuidv4()minted perPOST /) andcorrelationIdon error responses (arandomUUID()fallback outsiderequestContextStorage) — both are pinned withexpect.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 /:idexpects 204, receives 404) reproduces identically onmain(git diff main --statshows zero modifications to any tracked file in this PR), unrelated to this change.npx tsc --noEmit(project config): only the pre-existingsrc/routes/users.tssyntax errors present identically onmain.npx eslint tests/schema/subscriptions.test.ts— clean, no errors.