- Add OpenAPI schema endpoint at /openapi.json with proper logging - Make server exportable for testing by wrapping app.listen in module check - Add Jest test suite covering all API endpoints - Improve request logging with IP addresses and timestamps - Add development dependencies for testing (jest, supertest)
28 lines
740 B
JavaScript
28 lines
740 B
JavaScript
const request = require('supertest');
|
|
|
|
describe('API Endpoints', () => {
|
|
let app;
|
|
|
|
beforeAll(() => {
|
|
app = require('../index.js');
|
|
});
|
|
|
|
test('should return a random reason at root endpoint', async () => {
|
|
const response = await request(app)
|
|
.get('/')
|
|
.expect(200)
|
|
.expect('Content-Type', /application\/json/);
|
|
|
|
expect(response.body).toHaveProperty('reason');
|
|
expect(typeof response.body.reason).toBe('string');
|
|
});
|
|
|
|
test('should return health status at /health endpoint', async () => {
|
|
const response = await request(app)
|
|
.get('/health')
|
|
.expect(200)
|
|
.expect('Content-Type', /application\/json/);
|
|
|
|
expect(response.body).toEqual({ status: 'ok' });
|
|
});
|
|
}); |