21 lines
2 KiB
JavaScript
21 lines
2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {readFileSync} from 'node:fs';
|
|
import {runInNewContext} from 'node:vm';
|
|
import {nativeServiceURL,nativeServiceAccess,NATIVE_SERVICES} from '../control-panel/public/cp-v2/cp-v2-native-services.mjs';
|
|
const root=new URL('../control-panel/public/',import.meta.url);
|
|
test('CHOAM commodity entries retain their own real-goods identity and canonical legacy destination',()=>{
|
|
const source=readFileSync(new URL('cp-v2/v2.js',root),'utf8');
|
|
const menu=source.slice(0,source.indexOf(';const art=')),resolver=source.slice(source.indexOf('function legacyRoute('),source.indexOf('function go('));
|
|
const resolve=runInNewContext(menu+';'+resolver+';legacyRoute');
|
|
for(const id of ['commodity-listings','commodity-mine'])assert.equal(resolve(id).wid,'market');
|
|
assert.equal(resolve('exchange').pid,'commodity-listings');
|
|
assert.ok(source.indexOf("['commodity-listings','commodity-mine'].includes(item.id)")<source.indexOf('if(["realm/companies"'));
|
|
});
|
|
test('commodity adapter clamps scope and keeps the exchange service authenticated',()=>{
|
|
const spec=NATIVE_SERVICES['exchange-listings'];assert.equal(nativeServiceAccess(null,spec),false);assert.equal(nativeServiceAccess({permissions:[]},spec),true);
|
|
const mine=new URL(nativeServiceURL('exchange-listings',{initialTab:'mine'}));assert.equal(mine.searchParams.get('service'),'exchange');assert.equal(mine.searchParams.get('view'),'mine');assert.equal(mine.hash,'#exchange');
|
|
for(const initialTab of [undefined,'https://outside.test','staff'])assert.equal(new URL(nativeServiceURL('exchange-listings',{initialTab})).searchParams.has('view'),false);
|
|
const client=readFileSync(new URL('exchange.mjs',root),'utf8');assert.match(client,/\/api\/exchange\/listings\?view=/);assert.doesNotMatch(client,/method:\s*['"]POST/);assert.match(client,/Purchases, delivery and reclaiming stay in game/);
|
|
const entry=readFileSync(new URL('user-service-entry.mjs',root),'utf8');assert.match(entry,/pages:\['exchange'\].*modules:\['\.\/exchange\.mjs'\]/);
|
|
});
|

Staff