MC/website/tests/spice-crafting-cookbook.test.mjs

44 lines
2.9 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import {createHash} from 'node:crypto';
import {recipeCatalogue,recipeIcons} from '../scripts/recipe-catalogue.mjs';
import {itemLoreModel} from '../control-panel/public/item-lore-model.mjs';
const catalogue=JSON.parse(readFileSync(new URL('../data/cookbook/spice-crafting.json',import.meta.url)));
const grades=JSON.parse(readFileSync(new URL('../data/cookbook/item-grades.json',import.meta.url)));
const records=recipeCatalogue().filter(r=>catalogue.some(s=>s.id===r.output.id));
test('all seven new recipe cards use the exact native catalogue grade, base plus one',()=>{
assert.equal(records.length,7);
for(const spec of catalogue){
const recipe=records.find(r=>r.output.id===spec.id),card=itemLoreModel({...recipe.output,nativeMetadata:true});
assert.equal(card.quality,spec.quality);assert.equal(card.mark,spec.baseMark+1);
assert.equal(recipe.output.material,spec.material.toLowerCase());
assert.equal(recipe.output.name,spec.name);assert.equal(recipe.output.custom,true);
}
assert.equal(records.find(r=>r.output.id==='spice_soul_campfire').output.equipmentMark,4);
assert.equal(records.find(r=>r.output.id==='spice_campfire').output.equipmentMark,5);
});
test('cooker recipes preserve the raw-spice cross and four iron corners',()=>{
for(const recipe of records.filter(r=>r.shaped)){
assert.equal(recipe.station,'Crafting table');assert.equal(recipe.amount,1);assert.equal(recipe.grid.length,9);
for(const slot of [0,2,6,8])assert.equal(recipe.grid[slot].id,'iron_ingot');
for(const slot of [1,3,5,7]){assert.equal(recipe.grid[slot].id,'spice');assert.equal(recipe.grid[slot].custom,true);}
assert.equal(recipe.grid[4].material,recipe.output.material);assert.equal(recipe.grid[4].custom,false);
}
const coal=records.find(r=>r.id==='spice_coal');assert.equal(coal.shaped,false);
assert.deepEqual(coal.inputs.map(i=>i.id),['spice','coal']);assert.match(coal.inputs[1].name,/Charcoal/);
const tender=records.find(r=>r.id==='spice_tender');assert.equal(tender.shaped,false);
assert.deepEqual(tender.inputs.map(i=>[i.id,i.custom]),[['minecart',false],['spice_coal',true]]);
});
test('the seven Cookbook icons and catalogue are bound to the reviewed plugin source',()=>{
const source=grades.additionalSources.spiceCookersAndRails;
assert.equal(source.sourceCommit,'13a8f23247497ac5cd9d59b6869e19097ee307be');
const bytes=readFileSync(new URL('../data/cookbook/spice-crafting.json',import.meta.url));
assert.equal(createHash('sha256').update(bytes).digest('hex'),source.files['network/content-assets/cookbook/spice-crafting.json']);
const icons=new Map(recipeIcons(records));assert.equal(icons.size,7);
for(const icon of Object.values(source.icons))assert.equal(createHash('sha256').update(readFileSync(new URL('../data/cookbook/'+icon.path,import.meta.url))).digest('hex'),icon.sha256);
});