Files
dashy/tests/server/general.test.js
2026-05-02 19:10:05 +01:00

70 lines
2.1 KiB
JavaScript

// @vitest-environment node
import { describe, it, expect } from 'vitest';
import request from 'supertest';
const app = require('../../services/app');
describe('Healthcheck', () => {
it('GET /healthz returns 200 with status, uptime and version', async () => {
const res = await request(app).get('/healthz');
expect(res.status).toBe(200);
expect(res.headers['cache-control']).toBe('no-store');
const body = JSON.parse(res.text);
expect(body.status).toBe('ok');
expect(typeof body.uptime).toBe('number');
expect(body.uptime).toBeGreaterThanOrEqual(0);
expect(typeof body.version).toBe('string');
});
it('ignores POST', async () => {
const res = await request(app).post('/healthz');
expect(res.status).toBeLessThan(500);
expect(res.status).not.toBe(200);
});
});
describe('Config serving', () => {
it('GET /conf.yml returns the config', async () => {
const res = await request(app).get('/conf.yml');
expect(res.status).toBe(200);
expect(res.text).toContain('pageInfo');
});
it('GET /missing.yml returns 404 JSON', async () => {
const res = await request(app).get('/nonexistent.yml');
expect(res.status).toBe(404);
expect(JSON.parse(res.text).success).toBe(false);
});
});
describe('System info', () => {
it('returns host metadata', async () => {
const res = await request(app).get('/system-info');
expect(res.status).toBe(200);
const body = JSON.parse(res.text);
expect(body.meta.hostname).toBeDefined();
expect(body.meta.uptime).toBeGreaterThan(0);
expect(body.memory).toBeDefined();
});
it('ignores POST', async () => {
const res = await request(app).post('/system-info');
expect(res.status).toBeLessThan(500);
});
});
describe('Get user', () => {
it('returns JSON', async () => {
const res = await request(app).get('/get-user');
expect(res.status).toBe(200);
expect(typeof JSON.parse(res.text)).toBe('object');
});
});
describe('SPA fallback', () => {
it('serves content for unknown routes', async () => {
const res = await request(app).get('/some/nonexistent/route');
expect([200, 404]).toContain(res.status);
});
});