'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const Machine = require('../../src/specificClass'); // Phase 4 regression: after the AssetResolver cutover the node must // (a) derive supplier/type/units from the registry, not from saved config, // (b) hard-fail with a clear log if asset.model is missing, // (c) hard-fail if asset.unit is missing or not in registry's allowed set, // (d) succeed with a known good model + unit. function makeConfig({ model = 'hidrostal-H05K-S03R', unit = 'm3/h' } = {}) { return { general: { id: 'test-node', name: 'Pump-T', logging: { enabled: false } }, asset: { model, unit, curveUnits: { pressure: 'mbar', flow: unit, power: 'kW', control: '%' } }, functionality: { softwareType: 'rotatingmachine' }, }; } test('asset metadata is derived from the registry, not from config', () => { const m = new Machine(makeConfig()); assert.ok(m.assetMetadata, 'expected assetMetadata to be populated'); assert.equal(m.assetMetadata.supplier, 'Hidrostal'); assert.equal(m.assetMetadata.type, 'Centrifugal'); assert.ok(Array.isArray(m.assetMetadata.units)); assert.ok(m.assetMetadata.units.length > 0); }); test('valid model + unit yields working curve predictors', () => { const m = new Machine(makeConfig()); assert.equal(m.hasCurve, true); assert.equal(typeof m.predictFlow, 'object'); assert.equal(typeof m.predictPower, 'object'); }); test('missing model installs null predictors (degraded mode)', () => { const m = new Machine(makeConfig({ model: null })); assert.equal(m.hasCurve, false); assert.equal(m.predictFlow, null); assert.equal(m.predictPower, null); }); test('unknown model installs null predictors and logs', () => { const m = new Machine(makeConfig({ model: 'no-such-model-xyz' })); assert.equal(m.hasCurve, false); assert.equal(m.assetMetadata, null); }); test('unit not in registry allowed-set installs null predictors', () => { const m = new Machine(makeConfig({ unit: 'furlongs-per-fortnight' })); assert.equal(m.hasCurve, false); }); test('two machines with the same model get independent assetMetadata instances', () => { const a = new Machine(makeConfig()); const b = new Machine(makeConfig()); assert.notStrictEqual(a, b); assert.equal(a.assetMetadata.supplier, b.assetMetadata.supplier); });