forked from unimatrix/web
36 lines
2.8 KiB
JavaScript
36 lines
2.8 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {organisationRefitPlan,refitReputationLevel} from '../control-panel/public/organisation-refit-policy.mjs';
|
|
import {toolTemplate} from '../control-panel/public/tool-template-policy.mjs';
|
|
const org={kind:'clan',id:'11111111-1111-4111-8111-111111111111',tag:'UART'};
|
|
const item=mark=>({...toolTemplate('shovel',mark),kind:'shovel',instanceId:'22222222-2222-4222-8222-222222222222:0',revision:1,amount:1,originSeason:'S1',customName:'My old shovel'});
|
|
const plan=(i,extra={})=>organisationRefitPlan(i,{organisation:org,reputationLevel:100,season:'S2',...extra});
|
|
test('refit replaces one item, changes material, and retains original identity and origin season',()=>{
|
|
const before=item(2),after=plan(before);
|
|
assert.equal(after.consume.original.instanceId,after.output.instanceId);
|
|
assert.equal(after.output.material,'stone_shovel');assert.equal(after.output.amount,1);
|
|
assert.equal(after.output.originSeason,'S1');assert.equal(after.output.lastRefitSeason,'S2');
|
|
assert.equal(after.output.customName,before.customName);assert.equal(before.material,'wooden_shovel');
|
|
assert.equal(after.output.revision,2);assert.deepEqual(after.output.organisationGear,org);
|
|
});
|
|
test('existing enchantments scale proportionately without adding missing enchantments',()=>{
|
|
const before={...item(3),enchantments:{efficiency:1,vanishing_curse:1}},after=plan(before);
|
|
assert.deepEqual(after.output.enchantments,{efficiency:2,vanishing_curse:1});
|
|
assert.equal(after.qualityChanged,true);assert.equal(after.consume.templates.length,2);
|
|
const later=plan({...item(9),enchantments:{mending:1}});assert.deepEqual(later.output.enchantments,{mending:1});
|
|
});
|
|
test('reputation thresholds cannot be skipped; all three organisation kinds share the same policy',()=>{
|
|
assert.equal(refitReputationLevel(1),1);assert.equal(refitReputationLevel(4),8);
|
|
assert.throws(()=>plan(item(3),{reputationLevel:7}),/Reputation level 8/);
|
|
for(const kind of ['clan','company','politics'])assert.equal(plan(item(3),{organisation:{...org,kind}}).output.organisationGear.kind,kind);
|
|
assert.throws(()=>plan(item(3),{organisation:{...org,kind:'personal'}}),/organisation/);
|
|
});
|
|
test('ordinary refits cannot create Legendary, Mythic or Relics, skip tiers or accept forged profiles',()=>{
|
|
assert.throws(()=>plan(item(11)),/special acquisition/);
|
|
assert.throws(()=>plan(item(12)),/excluded/);
|
|
assert.throws(()=>plan({...item(3),quality:'relic'}),/excluded/);
|
|
assert.throws(()=>plan({...item(3),amount:2}),/one registered/);
|
|
assert.throws(()=>plan({...item(3),material:'netherite_shovel'}),/registered ladder/);
|
|
assert.throws(()=>plan({...item(3),enchantments:{efficiency:99}}),/registered refit profile/);
|
|
assert.throws(()=>plan({...item(3),enchantments:{constructor:1}}),/registered refit profile/);
|
|
});
|

Staff