71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
const request = require('supertest');
|
|
const express = require('express');
|
|
|
|
describe('Health and Basic Routes', () => {
|
|
let app;
|
|
|
|
beforeAll(() => {
|
|
// Create minimal test server with health endpoint
|
|
app = express();
|
|
app.use(express.json());
|
|
|
|
app.get('/api/health', (req, res) => {
|
|
res.json({
|
|
status: 'ok',
|
|
timestamp: new Date().toISOString(),
|
|
service: 'tilbudgivern-unified'
|
|
});
|
|
});
|
|
});
|
|
|
|
test('GET /api/health returns 200 OK', async () => {
|
|
const response = await request(app)
|
|
.get('/api/health')
|
|
.expect('Content-Type', /json/)
|
|
.expect(200);
|
|
|
|
expect(response.body).toHaveProperty('status', 'ok');
|
|
expect(response.body).toHaveProperty('service', 'tilbudgivern-unified');
|
|
expect(response.body).toHaveProperty('timestamp');
|
|
});
|
|
|
|
test('Health response has valid timestamp', async () => {
|
|
const response = await request(app).get('/api/health');
|
|
const timestamp = new Date(response.body.timestamp);
|
|
|
|
expect(timestamp).toBeInstanceOf(Date);
|
|
expect(timestamp.getTime()).toBeGreaterThan(Date.now() - 5000); // Within 5 seconds
|
|
});
|
|
});
|
|
|
|
describe('CORS and Security Headers', () => {
|
|
let app;
|
|
|
|
beforeAll(() => {
|
|
app = express();
|
|
|
|
// Simulate CORS middleware
|
|
app.use((req, res, next) => {
|
|
res.header('Access-Control-Allow-Origin', '*');
|
|
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
res.header('X-Content-Type-Options', 'nosniff');
|
|
next();
|
|
});
|
|
|
|
app.get('/test', (req, res) => res.json({ ok: true }));
|
|
});
|
|
|
|
test('Response includes CORS headers', async () => {
|
|
const response = await request(app).get('/test');
|
|
|
|
expect(response.headers).toHaveProperty('access-control-allow-origin');
|
|
expect(response.headers).toHaveProperty('access-control-allow-methods');
|
|
});
|
|
|
|
test('Response includes security headers', async () => {
|
|
const response = await request(app).get('/test');
|
|
|
|
expect(response.headers).toHaveProperty('x-content-type-options', 'nosniff');
|
|
});
|
|
});
|