import test from 'node:test'; import assert from 'node:assert/strict'; import {readFileSync} from 'node:fs'; import {runInNewContext} from 'node:vm'; import {nativeServiceURL} from '../control-panel/public/cp-v2/cp-v2-native-services.mjs'; const source=readFileSync(new URL('../control-panel/public/cp-v2/v2.js',import.meta.url),'utf8'); const menu=source.slice(0,source.indexOf(';const art=')); const resolver=source.slice(source.indexOf('function legacyRoute('),source.indexOf('function go(')); const resolve=runInNewContext(menu+';'+resolver+';legacyRoute'); test('legacy links resolve to the actual V2 User page instead of the default passport',()=>{ for(const id of ['game','security','rewards-codes','tickets']){const route=resolve(id);assert.equal(route.wid,'realm');assert.equal(route.pid,id);} for(const [id,workspace,page]of [['clans','clan','clan-overview'],['kits-exchange','kits','kits-exchange'],['quests','quests','quests']]){const route=resolve('realm',id);assert.equal(route.wid,workspace);assert.equal(route.pid,page);} assert.equal(resolve('clans').wid,'clan');assert.equal(resolve('kits-exchange').wid,'kits'); assert.equal(resolve('bank','bank-history').pid,'bank-statements');assert.equal(resolve('bank','bank-information').pid,'bank-overview');assert.equal(resolve('personal-bank').wid,'bank');assert.equal(resolve('realm','transactions').pid,'bank-statements');assert.equal(resolve('rewards-redeem').initialTab,'redeem');assert.equal(resolve('kit-checkout').initialTab,'kit-checkout');assert.equal(resolve('clan-inbox').pid,'clan-inbox');assert.equal(resolve('shared-inbox').wid,'post');assert.equal(resolve('realm','shared-inbox').wid,'post'); assert.equal(resolve('dev-queue').wid,'forge');assert.equal(resolve('bureau','permissions').pid,'permissions'); }); test('public kit purchase retains only a valid listing identity inside the fixed authenticated checkout destination',()=>{ const id='12345678-1234-4234-8234-123456789abc',url=new URL(nativeServiceURL('kits-exchange',{listingId:id}));assert.equal(url.origin,'https://cp.dunerealms.com');assert.equal(url.pathname,'/user-service.html');assert.equal(url.searchParams.get('service'),'tailor');assert.equal(url.searchParams.get('kit-listing'),id);assert.equal(url.hash,'#kit-checkout'); for(const listingId of ['https://outside.example','../secret','bad-id'])assert.equal(new URL(nativeServiceURL('kits-exchange',{listingId})).searchParams.has('kit-listing'),false); assert.equal(new URL(nativeServiceURL('shared-inbox',{initialTab:'clan-inbox'})).hash,'#clan-inbox');assert.equal(new URL(nativeServiceURL('shared-inbox',{initialTab:'https://outside.example'})).hash,'#shared-inbox'); }); test('public Kit Exchange links point at the canonical V2 workshop',()=>{ const entry=readFileSync(new URL('../web/kits.js',import.meta.url),'utf8'),exchange=readFileSync(new URL('../control-panel/public/cp-v2/cp-v2-exchange-design.mjs',import.meta.url),'utf8');assert.match(entry,/location\.replace\('\/exchange\.html\?type=kits'\)/);assert.match(exchange,/#realm\/kits-exchange/);assert.doesNotMatch(exchange,/#kit-checkout/); });