77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
const request = require('supertest');
|
|
const app = require('../../src/server');
|
|
|
|
describe('Health Check', () => {
|
|
test('GET /health returns 200', async () => {
|
|
const res = await request(app).get('/health');
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.status).toBe('ok');
|
|
expect(res.body.ts).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Metrics Endpoint', () => {
|
|
test('GET /metrics returns 200 with prometheus format', async () => {
|
|
const res = await request(app).get('/metrics');
|
|
expect(res.status).toBe(200);
|
|
expect(res.text).toContain('http_requests_total');
|
|
expect(res.text).toContain('process_cpu_user_seconds');
|
|
});
|
|
});
|
|
|
|
describe('Auth Flow', () => {
|
|
test('GET /login returns 200', async () => {
|
|
const res = await request(app).get('/login');
|
|
expect(res.status).toBe(200);
|
|
expect(res.text).toContain('Login');
|
|
});
|
|
|
|
test('GET /setup returns 200 when no users exist', async () => {
|
|
const res = await request(app).get('/setup');
|
|
// Should either show setup form or redirect to login
|
|
expect([200, 302]).toContain(res.status);
|
|
});
|
|
|
|
test('POST /login with empty body returns 200 with error', async () => {
|
|
const res = await request(app)
|
|
.post('/login')
|
|
.send({})
|
|
.set('Content-Type', 'application/x-www-form-urlencoded');
|
|
expect(res.status).toBe(200);
|
|
});
|
|
|
|
test('GET / redirects to /login when not authenticated', async () => {
|
|
const res = await request(app).get('/');
|
|
expect(res.status).toBe(302);
|
|
expect(res.headers.location).toBe('/login');
|
|
});
|
|
});
|
|
|
|
describe('Protected Routes', () => {
|
|
test('GET /loads redirects to login', async () => {
|
|
const res = await request(app).get('/loads');
|
|
expect(res.status).toBe(302);
|
|
});
|
|
|
|
test('GET /shippers redirects to login', async () => {
|
|
const res = await request(app).get('/shippers');
|
|
expect(res.status).toBe(302);
|
|
});
|
|
|
|
test('GET /payments redirects to login', async () => {
|
|
const res = await request(app).get('/payments');
|
|
expect(res.status).toBe(302);
|
|
});
|
|
|
|
test('GET /reports redirects to login', async () => {
|
|
const res = await request(app).get('/reports');
|
|
expect(res.status).toBe(302);
|
|
});
|
|
});
|
|
|
|
describe('404 Handler', () => {
|
|
test('GET /nonexistent returns 404', async () => {
|
|
const res = await request(app).get('/nonexistent-page');
|
|
expect(res.status).toBe(404);
|
|
});
|
|
});
|