import Image from ‘next/image’;
metadata.test.js Test Suite Documentation
Overview
This Jest test suite performs snapshot testing for the metadata of each entity defined in the metadata-cache.json. It ensures that the API’s metadata response for each entity remains consistent over time by comparing the current API response to previously saved snapshots.
Test Scope
- Iterates over all entities defined in the metadata cache.
- Sends a GET request to fetch the metadata for each entity.
- Compares the full metadata response against a stored Jest snapshot to detect unintended changes.
Test source
The base of the endpoint is hardcoded, but repeted for every entity. Snapshots are based on prior run.
Key Functionalities Tested
1. Metadata Retrieval
- For each entity, a GET request is sent to the API endpoint that exposes the entity’s metadata.
- The request is made without authentication headers (assuming open access).
2. Snapshot Comparison
- The JSON response containing the metadata is compared to an existing snapshot.
- Any difference between the current metadata and the snapshot will cause the test to fail, alerting developers to metadata changes.
Environmental Setup
- Uses environment variable:
PHPR_BASE_URL- Base URL for API requests.
- Loads test configuration from
metadata-cache.json.
Notes
- Snapshot testing is useful for tracking changes to API metadata, which could impact client integrations, other test suites or documentation.
- This suite expects snapshots to be committed and updated intentionally whenever metadata changes are authorized.
- Running these tests helps catch unexpected API schema or metadata modifications early.
- Includes a simple arithmetic test (
adds 1 + 1 to equal 2) as a baseline sanity check.
Last updated on