f500db971b
build-and-push / build-and-push (push) Successful in 1m26s
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>
48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
import { test, after } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { newApp } from './helpers.js';
|
|
|
|
test('server-types: full CRUD', async (t) => {
|
|
const app = await newApp();
|
|
after(() => app.close());
|
|
|
|
const created = await app.inject({
|
|
method: 'POST', url: '/api/server-types', payload: { name: 'Database' },
|
|
});
|
|
assert.equal(created.statusCode, 201);
|
|
const t1 = JSON.parse(created.body);
|
|
|
|
const dup = await app.inject({
|
|
method: 'POST', url: '/api/server-types', payload: { name: 'Database' },
|
|
});
|
|
assert.equal(dup.statusCode, 409);
|
|
|
|
const upd = await app.inject({
|
|
method: 'PUT', url: `/api/server-types/${t1.id}`, payload: { name: 'DB' },
|
|
});
|
|
assert.equal(JSON.parse(upd.body).name, 'DB');
|
|
|
|
const del = await app.inject({ method: 'DELETE', url: `/api/server-types/${t1.id}` });
|
|
assert.equal(del.statusCode, 204);
|
|
});
|
|
|
|
test('server-types: cannot delete one referenced by a host (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);
|
|
const room = JSON.parse((await app.inject({ method: 'POST', url: '/api/rooms', payload: { site_id: site.id, name: 'R' } })).body);
|
|
const type = JSON.parse((await app.inject({ method: 'POST', url: '/api/server-types', payload: { name: 'Web' } })).body);
|
|
|
|
await app.inject({
|
|
method: 'POST', url: '/api/hosts',
|
|
payload: {
|
|
hardware_id: 'HW', hostname: 'h', asset_id: 'A',
|
|
room_id: room.id, position: '', server_type_id: type.id,
|
|
},
|
|
});
|
|
|
|
const r = await app.inject({ method: 'DELETE', url: `/api/server-types/${type.id}` });
|
|
assert.equal(r.statusCode, 409);
|
|
});
|