MC/website/tests/company-cp-shell.test.mjs
2026-11-27 23:43:05 +00:00

23 lines
2.6 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';import {readFile} from 'node:fs/promises';
import {createPanel} from '../control-panel/server.mjs';import {LocalD1} from './d1-adapter.mjs';
import {COMPANY_MENU,companyPage} from '../control-panel/public/cp-v2/cp-v2-company-navigation.mjs';
test('Company CP clones the Clan frame, has isolated company navigation and permits its dedicated parent',async()=>{
const db=new LocalD1(),app=createPanel(db);try{
const response=await app(new Request('https://cp.dunerealms.com/company-cp'));assert.equal(response.status,200);const html=await response.text();
assert.match(html,/data-cp-mode="company"/);assert.match(html,/cp-v2-company-shell.mjs/);assert.match(html,/id="sidebar-right"/);assert.doesNotMatch(html,/src="\/v2\/v2.js|cp-v2-clan-size.mjs|class="dune-site-header"/);
assert.match(response.headers.get('content-security-policy'),/frame-ancestors[^;]*https:\/\/corp.dunerealms.com/);
const policy=response.headers.get('content-security-policy');
assert.match(policy,/img-src 'self' data: https:\/\/www.dunerealms.com(?:;|$)/,'Company portraits and CSS backgrounds must load from the canonical artwork host');
assert.doesNotMatch(policy,/img-src[^;]*(?:https:;|\*)/,'Artwork permission must remain limited to the canonical host');
assert.equal((await app(new Request('https://cp.dunerealms.com/company-cp',{method:'POST'}))).status,405);
assert.equal((await app(new Request('https://cp.dunerealms.com/api/companies/workspace'))).status,401);
for(const path of ['cp-v2-company-shell.mjs','cp-v2-company-shell.css','cp-v2-policy-catalogue.mjs','cp-v2-claims.mjs'])assert.equal((await app(new Request('https://cp.dunerealms.com/v2/'+path))).status,200);
}finally{db.close();}
assert.equal(companyPage('#company/claims'),'claims');assert.equal(companyPage('#company/unknown'),'overview');assert.ok(COMPANY_MENU.some(([id])=>id==='subsidiaries'));
});
test('Companies is relocated from personal menus and clan claims/subhouses remain under Clan CP',async()=>{
const source=await readFile(new URL('../control-panel/public/cp-v2/v2.js',import.meta.url),'utf8'),menu=JSON.parse(source.slice(source.indexOf('=')+1,source.indexOf(';')));
assert.ok(!menu.workspaces.find(w=>w.id==='realm').groups.flatMap(g=>g.items).some(i=>i.id==='companies'));
const clan=menu.workspaces.find(w=>w.id==='clan').groups.flatMap(g=>g.items);assert.ok(clan.some(i=>i.id==='clan-claims'));assert.ok(clan.some(i=>i.id==='clan-subhouses'));
const html=await readFile(new URL('../ops/company-center-index.html',import.meta.url),'utf8');assert.match(html,/company-workspace/);assert.match(html,/company-cp#company\/overview/);
});