test(devices): add response schema stability snapshot test for /api/devices - #710
Open
therealbibson wants to merge 1 commit into
Open
Conversation
…evices Adds tests/schema/devices.test.ts with snapshot assertions that the response shape of GET /api/me/devices does not drift accidentally. Tests cover envelope structure, device field types, family collapsing, sorting order, and empty-state response. Closes Predictify-org#648
|
@therealbibson Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Overview
This pull request adds a focused schema-stability (snapshot) test suite for the GET /api/me/devices endpoint. The devices endpoint returns a list of active refresh-token sessions collapsed by family, and until now there was no guard against accidental changes to its response shape. A consumer relying on the documented structure could break silently if a future change modifies the envelope.
The new test file (tests/schema/devices.test.ts) asserts the canonical response envelope shape, field types, token-family collapsing behaviour, sort order, and empty-state response. It uses Jest snapshot matchers (with variable data like dates replaced by placeholders) to detect any drift in the JSON structure -- providing both a runtime assertion and a review-time diff when the shape intentionally changes.
Related Issue
Closes #648 -- Add response schema stability test for /api/devices [b#074]
Changes
Added File: tests/schema/devices.test.ts
This file contains a comprehensive test suite with the following test cases:
1. Canonical Envelope Shape Assertion
2. Empty-State Response
3. Token-Family Collapsing
4. Newest-First Sort Order
Test Infrastructure
Testing and Verification
Running the Tests
cd predictify-backend
npm test -- --testPathPatterns=tests/schema/devices
Expected Output
Snapshot Management
Acceptance Criteria
Security Considerations
This PR addresses issue #648 as part of the GrantFox FWC26 campaign. All changes adhere to the repository's coding style, lint rules, and testing conventions.