forked from unimatrix/web
50 lines
3.3 KiB
JavaScript
50 lines
3.3 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {readFileSync} from 'node:fs';
|
|
import {recipeCatalogue,withRecipeGrade} from '../scripts/recipe-catalogue.mjs';
|
|
import {itemLoreModel} from '../control-panel/public/item-lore-model.mjs';
|
|
|
|
test('all Cookbook outputs have source-bound grades or explicitly preserve input metadata',()=>{
|
|
const recipes=recipeCatalogue(),metadata=JSON.parse(readFileSync(new URL('../data/cookbook/item-grades.json',import.meta.url)));
|
|
assert.equal(recipes.length,46);assert.equal(new Set(recipes.map(r=>r.output.id)).size,39);
|
|
assert.equal(metadata.sourceRepository,'unimatrix/plugins');assert.match(metadata.sourceCommit,/^[a-f0-9]{40}$/);
|
|
for(const hash of Object.values(metadata.files))assert.match(hash,/^[a-f0-9]{64}$/);
|
|
for(const recipe of recipes){
|
|
const definition=metadata.items[recipe.output.id];assert.ok(definition,recipe.id);assert.equal(recipe.output.material,definition.material);
|
|
if(definition.mode==='input'){
|
|
assert.equal(recipe.id,'spice_boosted_potion');assert.equal(recipe.output.metadataMode,'input');
|
|
assert.equal(recipe.output.quality,undefined);assert.equal(recipe.output.equipmentMark,undefined);continue;
|
|
}
|
|
const card=itemLoreModel({...recipe.output,nativeMetadata:true});
|
|
assert.equal(card.quality,definition.quality);assert.equal(card.mark,definition.equipmentMark);
|
|
assert.doesNotMatch(card.qualityLabel,/not registered/);assert.doesNotMatch(card.markLabel,/not registered/);
|
|
}
|
|
});
|
|
|
|
test('previously missing output grades reach the shared item card without deriving them from device names',()=>{
|
|
const recipes=recipeCatalogue(),get=id=>recipes.find(r=>r.output.id===id).output;
|
|
for(const [id,quality,mark] of [
|
|
['jerboa_leather','uncommon',3],['spice_bread','very_rare',9],
|
|
['spice_block','uncommon',2],['smuggled_spice_block','uncommon',3],
|
|
['crafted_elytra','very_rare',11],['jerboa_water_vial','rare',6],['water_of_life','very_rare',7],
|
|
['dunechest_ender_chest','very_rare',9],['dunechest_auto_crafter','uncommon',3],
|
|
['dunechest_wrench','very_rare',10],['dunechest_dune_beacon','rare',8],
|
|
...[1,2,3].map(t=>['dunechest_speed_hopper_'+t,'uncommon',3]),
|
|
]){assert.equal(get(id).quality,quality,id);assert.equal(get(id).equipmentMark,mark,id);}
|
|
const powercore=itemLoreModel(get('dunechest_dune_beacon'));
|
|
assert.match(powercore.title,/MK XIV/);assert.equal(powercore.markLabel,'MK VIII');assert.equal(powercore.qualityLabel,'Rare');
|
|
assert.equal(get('dunechest_ender_chest').material,'ender_chest');
|
|
const ingredient=recipes.find(r=>r.id==='dunechest_speed_hopper_2').grid[4];
|
|
assert.equal(ingredient.id,'dunechest_speed_hopper_1');
|
|
});
|
|
|
|
test('missing, conflicting or material-mismatched metadata cannot silently produce unknown item grades',()=>{
|
|
const output={id:'fixture',material:'hopper'};
|
|
const grade={material:'hopper',quality:'uncommon',equipmentMark:3};
|
|
assert.throws(()=>withRecipeGrade(output,undefined),/Missing/);
|
|
assert.throws(()=>withRecipeGrade(output,{...grade,material:'barrel'}),/mismatched/);
|
|
assert.throws(()=>withRecipeGrade(output,{...grade,equipmentMark:15}),/Invalid/);
|
|
assert.throws(()=>withRecipeGrade({...output,quality:'legendary'},grade),/conflicts/);
|
|
assert.throws(()=>withRecipeGrade(output,{...grade,mode:'input'}),/fixed grade/);
|
|
assert.equal(withRecipeGrade({...output,name:'Anything MK XIV'},grade).equipmentMark,3);
|
|
});
|

Staff