nomadro/tests/portal-smoke.mjs

27 lines
1.1 KiB
JavaScript

import assert from 'node:assert/strict';
// Run against a local `next start`; no production API calls or mutations.
const origin = process.env.PORTAL_SMOKE_ORIGIN || 'http://127.0.0.1:3114';
assert.ok(['127.0.0.1', 'localhost'].includes(new URL(origin).hostname));
for (const [path, status, location] of [
['/', 200],
['/social?smoke=1', 308, '/?smoke=1'],
['/ebook', 308, '/book'],
['/notifications/settings', 308, '/social/notifications/settings'],
['/vip', 200],
['/nav', 200],
]) {
const response = await fetch(new URL(path, origin), {
redirect: 'manual', signal: AbortSignal.timeout(20000),
});
assert.equal(response.status, status, path);
if (location) {
const target = new URL(response.headers.get('location'), origin);
assert.equal(target.pathname + target.search, location, path);
}
assert.equal(response.headers.get('x-content-type-options'), 'nosniff', path);
const body = await response.text();
if (path === '/') assert.ok(body.includes('community-root social-skin'), 'Social home layout must render at /');
console.log(`${path}: ${status} OK`);
}