web/website/tests/patronage-preview.test.mjs
2026-11-27 23:43:05 +00:00

19 lines
1.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {deedPreviewRows,patronageEmblem} from '../control-panel/public/cp-v2/cp-v2-patronage.mjs';
const deed=(id,extra={})=>({id:String(id),category:'deeds',organisationKind:'company',quantity:1,price:'100.00',...extra});
test('company and clan previews stay separate and never advertise protected or unclassified deeds',()=>{
const rows=[deed(1),deed(2,{organisationKind:'clan'}),deed(3,{protected:true}),deed(4,{organisationType:'passive-order'}),deed(5,{organisationKind:'politics'}),deed(6,{organisationKind:undefined}),deed(7,{institutionKey:'order-crysknife'})];
assert.deepEqual(deedPreviewRows(rows,{kind:'company'}).map(x=>x.id),['1']);
assert.deepEqual(deedPreviewRows(rows,{kind:'clan'}).map(x=>x.id),['2']);
});
test('preview keeps at most five valid, positive-price entries and supports existing UUID listing references',()=>{
const rows=[deed(1,{price:'NaN'}),deed(2,{price:'-10'}),deed(3,{quantity:0}),deed('6497e35e-1617-4f59-ac79-3ca0f040aa89'),...Array.from({length:9},(_,i)=>deed(i+4))];
assert.equal(deedPreviewRows(rows,{kind:'company'}).length,5);
assert.equal(deedPreviewRows(rows,{kind:'company'})[0].id,'6497e35e-1617-4f59-ac79-3ca0f040aa89');
});
test('real central emblem URLs are usable; arbitrary origins and executable URLs are rejected',()=>{
assert.equal(patronageEmblem('https://cp.dunerealms.com/api/company-emblems/example?v=2'),'https://cp.dunerealms.com/api/company-emblems/example?v=2');
assert.ok(patronageEmblem('/api/clan-emblems/example'));
for(const url of ['javascript:alert(1)','https://outside.invalid/icon.png','https://cp.dunerealms.com/api/auth/session'])assert.equal(patronageEmblem(url),null);
});