Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tests/contract/api-schemas.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @fileoverview API Response Schema Contract Tests
* Validates that API responses adhere to expected data structures.
*/

const request = require('supertest');
const { createApp } = require('../../src/app');

describe('API Contract Tests - Response Schemas', () => {
let app;

beforeAll(() => {
app = createApp();
});

it('should match the GET /health response schema', async () => {
const res = await request(app).get('/health');
expect(res.status).toBe(200);
expect(res.body).toEqual(
expect.objectContaining({
status: expect.any(String),
service: expect.any(String),
version: expect.any(String),
timestamp: expect.any(String),
})
);
});

it('should match the GET /api/invoices response schema', async () => {
const res = await request(app).get('/api/invoices');
expect(res.status).toBe(200);
expect(res.body).toEqual(
expect.objectContaining({
data: expect.any(Array),
message: expect.any(String),
})
);
});

it('should match the POST /api/invoices response schema', async () => {
const res = await request(app).post('/api/invoices').send({});
expect(res.status).toBe(201);
expect(res.body).toEqual(
expect.objectContaining({
data: expect.objectContaining({
id: expect.any(String),
status: expect.any(String),
}),
message: expect.any(String),
})
);
});
});
Loading