@@ -0,0 +1,49 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { validateConfig } from '../services/configValidation.js';
|
||||
import { generateCuttingList } from '../services/cuttingEngine.js';
|
||||
|
||||
function run() {
|
||||
const baseConfig = {
|
||||
installationType: 'free',
|
||||
widthMm: 2400,
|
||||
heightMm: 2400,
|
||||
depthMm: 610,
|
||||
plinthHeightMm: 100,
|
||||
modules: [{ type: 'tiroirs', widthMm: 900, drawers: 3, hasRod: false }],
|
||||
doorType: 'hinged',
|
||||
hardware: {
|
||||
handleBoreHeightMm: 1000,
|
||||
drawerType: 'visible'
|
||||
}
|
||||
};
|
||||
|
||||
const okValidation = validateConfig(baseConfig, { allow_sliding_doors: '0' });
|
||||
assert.equal(okValidation.errors.length, 0, 'Base config should be valid');
|
||||
|
||||
const invalidDrawerConfig = {
|
||||
...baseConfig,
|
||||
modules: [{ type: 'tiroirs', widthMm: 1201, drawers: 2, hasRod: false }]
|
||||
};
|
||||
const invalidDrawerValidation = validateConfig(invalidDrawerConfig, {});
|
||||
assert.ok(
|
||||
invalidDrawerValidation.errors.some((e) => String(e.message).includes('1000')),
|
||||
'Drawer width limit should trigger validation error'
|
||||
);
|
||||
|
||||
const nonStandardHandle = {
|
||||
...baseConfig,
|
||||
hardware: { ...baseConfig.hardware, handleBoreHeightMm: 1450 }
|
||||
};
|
||||
const nonStandardHandleValidation = validateConfig(nonStandardHandle, {});
|
||||
assert.ok(nonStandardHandleValidation.warnings.length > 0, 'Handle warning should be emitted');
|
||||
|
||||
const cuttingList = generateCuttingList(baseConfig, {}, baseConfig.modules);
|
||||
const sidePiece = cuttingList.pieces.find((p) => p.elementType === 'cotes');
|
||||
assert.ok(sidePiece?.machining?.groove, 'Side piece should include groove machining');
|
||||
assert.equal(sidePiece.machining.groove.width, 9, 'Groove width should be 9mm');
|
||||
assert.equal(sidePiece.machining.groove.depth, 10.5, 'Groove depth should be 10.5mm');
|
||||
assert.equal(sidePiece.machining.groove.axisFromPanelEdge, 16, 'Groove position should be 16mm from edge');
|
||||
}
|
||||
|
||||
run();
|
||||
console.log('rules.spec.mjs: all assertions passed');
|
||||
Reference in New Issue
Block a user