Files
Infrastructure/tests/sites.test.js
T
josh f500db971b
build-and-push / build-and-push (push) Successful in 1m26s
Initial commit: Infrastructure host tracking app
Fastify + node:sqlite single-process app with vanilla JS UI for
looking up hosts by hardware ID, hostname, or asset ID. Includes
per-host network interface tracking, sites/rooms/server-types CRUD,
Docker packaging, and a Gitea Actions workflow that runs tests then
builds and pushes to gitea.thewrightserver.net/josh/infrastructure.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-19 17:05:50 -04:00

55 lines
1.8 KiB
JavaScript

import { test, after } from 'node:test';
import assert from 'node:assert/strict';
import { newApp } from './helpers.js';
test('sites: full CRUD', async (t) => {
const app = await newApp();
after(() => app.close());
const empty = await app.inject({ method: 'GET', url: '/api/sites' });
assert.deepEqual(JSON.parse(empty.body), []);
const created = await app.inject({
method: 'POST', url: '/api/sites', payload: { name: 'DC1' },
});
assert.equal(created.statusCode, 201);
const site = JSON.parse(created.body);
assert.equal(site.name, 'DC1');
const list = await app.inject({ method: 'GET', url: '/api/sites' });
assert.equal(JSON.parse(list.body).length, 1);
const upd = await app.inject({
method: 'PUT', url: `/api/sites/${site.id}`, payload: { name: 'DC2' },
});
assert.equal(upd.statusCode, 200);
assert.equal(JSON.parse(upd.body).name, 'DC2');
const del = await app.inject({ method: 'DELETE', url: `/api/sites/${site.id}` });
assert.equal(del.statusCode, 204);
});
test('sites: duplicate name returns 409', async (t) => {
const app = await newApp();
after(() => app.close());
await app.inject({ method: 'POST', url: '/api/sites', payload: { name: 'A' } });
const dup = await app.inject({ method: 'POST', url: '/api/sites', payload: { name: 'A' } });
assert.equal(dup.statusCode, 409);
});
test('sites: cannot delete site that has rooms (409)', async (t) => {
const app = await newApp();
after(() => app.close());
const site = JSON.parse((await app.inject({
method: 'POST', url: '/api/sites', payload: { name: 'S' },
})).body);
await app.inject({
method: 'POST', url: '/api/rooms',
payload: { site_id: site.id, name: 'R' },
});
const r = await app.inject({ method: 'DELETE', url: `/api/sites/${site.id}` });
assert.equal(r.statusCode, 409);
});