39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
// test/restart-check.mjs -- after a server restart: the token
|
|
// survives, the boot-rebuild reopened the unhousekept sessions, the
|
|
// runs list is whole. Reads the token + run ids smoke.mjs left in
|
|
// the temp file; run against the restarted --mock server:
|
|
// node test/restart-check.mjs
|
|
|
|
import { readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { tmpdir } from 'node:os';
|
|
|
|
const BASE = process.env.RP_BASE ?? 'http://127.0.0.1:7350';
|
|
const [token, reforkId, secondId] = readFileSync(join(tmpdir(), 'tiny-worlds-smoke-token.txt'), 'utf8').trim().split(' ');
|
|
const call = async (path, tok) => {
|
|
const res = await fetch(`${BASE}/api${path}`, {
|
|
headers: tok ? { authorization: `Bearer ${tok}` } : {},
|
|
});
|
|
return { status: res.status, data: await res.json().catch(() => ({})) };
|
|
};
|
|
let failures = 0;
|
|
const ok = (name, cond, extra = '') => {
|
|
console.log(`${cond ? 'PASS' : 'FAIL'} ${name}${extra ? ` -- ${extra}` : ''}`);
|
|
if (!cond) failures++;
|
|
};
|
|
|
|
let r = await call('/session', token);
|
|
ok('token survives restart', r.status === 200 && r.data.user?.name === 'Op');
|
|
|
|
r = await call(`/runs/${reforkId}`, token);
|
|
ok('forked session rebuilt', r.status === 200 && r.data.open === true, JSON.stringify({ open: r.data.open, owner: r.data.run.owner }));
|
|
|
|
r = await call(`/runs/${secondId}`, token);
|
|
ok('draft intact', r.status === 200 && r.data.draft === true);
|
|
|
|
r = await call('/runs', token);
|
|
ok('runs listed', r.status === 200 && Array.isArray(r.data) && r.data.length >= 4, `${r.data.length} runs`);
|
|
|
|
console.log(failures ? `\n${failures} FAILURES` : '\nALL PASS');
|
|
process.exit(failures ? 1 : 0);
|