MC/website/tests/equipment-template-policy.test.mjs
2026-11-27 23:43:05 +00:00

49 lines
4.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {equipmentTemplate,EQUIPMENT_QUALITY_STYLES,qualityForMark,maximumEquipmentEnchantments,validateEquipmentEnchantments} from '../control-panel/public/equipment-template-policy.mjs';
import {nativeKit} from '../../tools/generate-native-kit.mjs';
import {defaultKitEquipment} from '../control-panel/public/kit-design-model.mjs';
test('fifteen normal marks follow the quality ladder with bounded profiles',()=>{
for(let mark=0;mark<=14;mark++){
const quality=qualityForMark(mark);
const template=equipmentTemplate({quality,mark});
for(const [slot,bounds] of Object.entries(template.enchantments)){
const values=maximumEquipmentEnchantments(template,slot);
assert.deepEqual(validateEquipmentEnchantments(template,slot,values),values);
for(const [id,{min,max}] of Object.entries(bounds)){
assert.ok(max>=min);
if(mark&&qualityForMark(mark-1)===quality)assert.ok(max>=equipmentTemplate({quality,mark:mark-1}).enchantments[slot][id].max);
}
}
}
});
test('max mark bounds enchantments; crossed qualities and future seasons are rejected',()=>{
assert.throws(()=>equipmentTemplate({quality:'legendary',mark:0}));
assert.throws(()=>equipmentTemplate({quality:'common',mark:14}));
const template=equipmentTemplate({quality:'legendary',mark:14}),helmet=maximumEquipmentEnchantments(template,'helmet');
assert.equal(helmet.protection,6);assert.equal(helmet.unbreaking,4);assert.equal(helmet.mending,1);assert.equal(helmet.aqua_affinity,1);
assert.throws(()=>validateEquipmentEnchantments(template,'helmet',{...helmet,protection:7}));
assert.throws(()=>validateEquipmentEnchantments({...template,enchantments:{helmet:{protection:{max:255}}}},'helmet',{...helmet,protection:255}));
for(const mark of [-1,15,14.5,NaN])assert.throws(()=>equipmentTemplate({quality:'legendary',mark}));
assert.throws(()=>equipmentTemplate({quality:'legendary',mark:14,season:'S2'}));
});
test('Mythic is the MK14 superclass with distinct colours and fixed single-level effects',()=>{
for(let mark=0;mark<14;mark++)assert.throws(()=>equipmentTemplate({quality:'mythic',mark}));
const template=equipmentTemplate({quality:'mythic',mark:14}),helmet=maximumEquipmentEnchantments(template,'helmet');
assert.equal(helmet.protection,7);assert.equal(helmet.unbreaking,5);assert.equal(helmet.mending,1);assert.equal(helmet.aqua_affinity,1);
assert.equal(EQUIPMENT_QUALITY_STYLES.mythic.code,'&d');assert.equal(EQUIPMENT_QUALITY_STYLES.very_rare.code,'&5');assert.equal(EQUIPMENT_QUALITY_STYLES.legendary.code,'&6');
const native=nativeKit({quality:'mythic',mark:14}).pieces[0];
assert.match(native.yaml,/&d&lImperial/);assert.match(native.yaml,/enchantment: protection\n level: 7/);assert.match(native.yaml,/enableRarity: false/);
});
test('native test kit writes actual enchantments matching its lore without granting commands',()=>{
const kit=nativeKit();assert.equal(kit.pieces.length,4);
for(const piece of kit.pieces){assert.match(piece.yaml,/keepDefaultAttributes: true/);assert.match(piece.yaml,/ignoreKeepDefaultAttributesFeature: false/);assert.match(piece.yaml,/itemModel: dunerealms:equipment\/legendary_mk14_/);assert.match(piece.yaml,/LEGENDARY.*MK XIV/);assert.match(piece.yaml,/S1 · Imperial Atelier/);assert.doesNotMatch(piece.yaml,/playerCommands|SUDO|unbreakable: true|s1-equipment|LORE TEST|────────────────/);assert.match(piece.yaml,/enchantment: protection\n level: 6/);}
assert.equal(nativeKit({quality:'common',mark:0}).pieces[0].enchantments.protection,undefined);
});
test('kit export retains each armour piece trim pattern and material',()=>{
const equipment=defaultKitEquipment();equipment.armor.helmet.trim={pattern:'spire',material:'amethyst'};equipment.armor.chestplate.trim={pattern:'dune',material:'gold'};equipment.armor.leggings.trim={pattern:'coast',material:'emerald'};equipment.armor.boots.trim={pattern:'sentry',material:'copper'};
const kit=nativeKit({equipment});for(const piece of kit.pieces){assert.deepEqual(piece.trim,equipment.armor[piece.slot].trim);assert(piece.yaml.includes('armorTrim:\n pattern: '+piece.trim.pattern.toUpperCase()+'\n material: '+piece.trim.material.toUpperCase()));}
assert.throws(()=>nativeKit({equipment:{...equipment,armor:{...equipment.armor,helmet:{...equipment.armor.helmet,trim:{pattern:'invented',material:'gold'}}}}}));
});