Mocking & Simulation
Mocking & Simulation
To facilitate rapid development and reliable testing without dependency on live API environments, this repository provides a standardized response.json file. This file acts as the "Source of Truth" for the Supervised AI platform's response schema, allowing you to simulate API behavior locally.
Using response.json for Local Development
When developing frontend components or downstream microservices, you can use the provided response.json to simulate the API's payload. This ensures that your application logic correctly handles the platform's data structure before integration.
Option 1: Static Import
If your development environment supports JSON imports (e.g., Webpack, Vite, or Node.js with ESM), you can import the mock data directly into your service logic:
import mockResponse from '@supervised-ai/testing-api/response.json';
// Use mockResponse to hydrate your local state or UI
console.log(mockResponse.data);
Option 2: Local Mock Server
For a more realistic simulation involving network latency and HTTP status codes, use a tool like json-server to serve the file:
# Install json-server
npm install -g json-server
# Start the mock server using the provided response file
json-server --watch response.json --port 3001
Your local application can then point its BASE_URL to http://localhost:3001 to fetch the mock data.
Integration with Unit Tests
Incorporate response.json into your test suites to ensure your parsers, transformers, and UI components are resilient to the platform's response structure.
Example: Mocking a Fetch Request with Jest
Using the mock data ensures your tests remain deterministic and do not require network access.
import mockResponse from './path/to/response.json';
describe('Supervised AI Integration', () => {
it('should correctly parse the platform response', async () => {
// Mocking the global fetch or an API client
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve(mockResponse),
})
);
const data = await myApiService.getData();
// Assert against the structure defined in response.json
expect(data).toHaveProperty('id');
expect(data.status).toBe('success');
});
});
Response Structure Reference
The response.json file adheres to the official Supervised AI API specification. While the specific values may vary based on your local edits, the root structure typically includes:
| Field | Type | Description |
| :--- | :--- | :--- |
| metadata | Object | Contains pagination, request IDs, and timestamping. |
| data | Object/Array | The primary payload (e.g., model outputs, training status). |
| errors | Array | A list of error objects (empty if the request is successful). |
Note: This structure is internal to the Supervised AI testing framework but is exposed here to provide developers with a stable interface for integration testing. Always ensure your local copy of
response.jsonis synced with the latest version of this repository to avoid schema drift.