Files
boss/tests/admin-domain-routing.test.ts
2026-06-08 12:22:50 +08:00

48 lines
1.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
const appRootPath = new URL("../src/app/page.tsx", import.meta.url);
const appUiPath = new URL("../src/components/app-ui.tsx", import.meta.url);
const bossAuthPath = new URL("../src/lib/boss-auth.ts", import.meta.url);
const caddyfilePath = new URL("../deployment/Caddyfile", import.meta.url);
async function readSource(path: URL) {
return readFile(path, "utf8");
}
test("admin host root uses the admin web shell as the platform console", async () => {
const source = await readSource(appRootPath);
assert.match(source, /headers/);
assert.match(source, /admin\.boss\.hyzq\.net/);
assert.match(source, /redirect\(session \? "\/admin-web\/index\.html" : "\/auth\/login"\)/);
});
test("web login returns admin host users to the admin console", async () => {
const source = await readSource(appUiPath);
assert.match(source, /admin\.boss\.hyzq\.net/);
assert.match(source, /navigateAfterLogin/);
assert.match(source, /\?\s*"\/"\s*:\s*"\/conversations"/);
});
test("authenticated admin host users return to the admin root domain", async () => {
const source = await readSource(bossAuthPath);
assert.match(source, /headers/);
assert.match(source, /admin\.boss\.hyzq\.net/);
assert.match(source, /redirect\("\/"\)/);
});
test("Caddy serves the platform admin subdomain", async () => {
const source = await readSource(caddyfilePath);
assert.match(source, /admin\.boss\.hyzq\.net/);
assert.match(source, /handle \/admin-web\/\* \{\s*root \* \/opt\/boss\/public\s*file_server\s*\}/s);
assert.match(source, /@adminRoot path \//);
assert.match(source, /rewrite \* \/admin-web\/index\.html/);
assert.doesNotMatch(source, /redir \/ \/enterprise-admin/);
assert.match(source, /reverse_proxy 127\.0\.0\.1:3000/);
});