feat: add OpenAPI documentation and comprehensive test suite

- 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)
This commit is contained in:
2025-09-02 12:26:30 +02:00
parent 69c216a0d0
commit 271eb107a2
5 changed files with 5598 additions and 5 deletions

23
test/openapi.test.js Normal file
View File

@@ -0,0 +1,23 @@
const request = require('supertest');
const fs = require('fs');
describe('OpenAPI Schema Endpoint', () => {
let app;
beforeAll(() => {
// Import the app after modifications
app = require('../index.js');
});
test('should serve OpenAPI schema at /openapi.json', async () => {
// Read the expected schema from the file
const expectedSchema = JSON.parse(fs.readFileSync('./openapi.json', 'utf-8'));
const response = await request(app)
.get('/openapi.json')
.expect(200)
.expect('Content-Type', /application\/json/);
expect(response.body).toEqual(expectedSchema);
});
});