web/website/tests/item-design-model.test.mjs
2026-11-27 23:43:05 +00:00

18 lines
1.8 KiB
JavaScript

import test from 'node:test';import assert from 'node:assert/strict';
import {defaultItemDesign,itemDesignTemplate,validateItemDesign} from '../control-panel/public/item-design-model.mjs';
test('a standalone item and a kit piece use the same required quality, MK and bounded enchantments',()=>{
for(const id of ['dr_s1_spice_shovel_mk1','dr_s1_sword_mk14','dr_s1_legendary_mk14_helmet','refined_spice','dr_imperial_codex']){
const item=defaultItemDesign(id);assert.deepEqual(validateItemDesign(item),item);for(const field of ['quality','equipmentMark','itemClass']){const incomplete={...item};delete incomplete[field];assert.throws(()=>validateItemDesign(incomplete));}
}
});
test('changing a submitted bound, class, material or command cannot create a stronger item',()=>{
const item=defaultItemDesign('dr_s1_legendary_mk14_helmet');
for(const patch of [{enchantments:{...item.enchantments,protection:255}},{equipmentMark:15},{quality:'mythic'},{itemClass:'relic'},{material:'bedrock'},{commands:['op player']},{enchantments:{...item.enchantments,fortune:7}}])assert.throws(()=>validateItemDesign({...item,...patch}));
assert.equal(itemDesignTemplate(item.templateId).enchantments.protection.max,6);
});
test('designed lore and armour trim survive validation without changing tools or embedded native behaviours',()=>{
const item=defaultItemDesign('dr_s1_legendary_mk14_chestplate');item.trim={pattern:'dune',material:'gold'};item.lore=[{text:'Forged for the long desert.',color:'#ffaa00',bold:false,italic:true}];const saved=validateItemDesign(item);assert.equal(saved.lore[0].color,'#FFAA00');assert.deepEqual(saved.trim,item.trim);
assert.throws(()=>validateItemDesign({...defaultItemDesign('dr_s1_spice_shovel_mk1'),trim:item.trim}));
assert.throws(()=>validateItemDesign({...item,lore:[{text:'<script>',color:'#FFFFFF',bold:false,italic:false}]}));
});