const test = require('node:test'); const assert = require('node:assert/strict'); const NodeClass = require('../../src/nodeClass'); const Machine = require('../../src/specificClass'); const { makeNodeStub } = require('../helpers/factories'); // After the BaseNodeAdapter migration, _loadConfig + _setupSpecificClass // are gone — config building lives in buildDomainConfig(). These tests // drive that contract through a prototype-derived nodeClass instance so // we exercise the surface without booting Node-RED. function makeUiConfig(overrides = {}) { return { unit: 'm3/h', enableLog: false, logLevel: 'error', supplier: 'hidrostal', category: 'machine', assetType: 'pump', model: 'hidrostal-H05K-S03R', curvePressureUnit: 'mbar', curveFlowUnit: 'm3/h', curvePowerUnit: 'kW', curveControlUnit: '%', positionVsParent: 'atEquipment', speed: 1, movementMode: 'staticspeed', startup: 0, warmup: 0, shutdown: 0, cooldown: 0, ...overrides, }; } function callBuildDomainConfig(ui) { const inst = Object.create(NodeClass.prototype); // Clear any leftover pending extras so this test's call is the only one // that stamps Machine._pendingExtras. Machine._pendingExtras = null; return inst.buildDomainConfig(ui); } test('buildDomainConfig maps legacy editor fields for asset identity', () => { const cfg = callBuildDomainConfig(makeUiConfig({ uuid: 'uuid-from-editor', assetTagNumber: 'TAG-123' })); assert.equal(cfg.asset.uuid, 'uuid-from-editor'); assert.equal(cfg.asset.tagCode, 'TAG-123'); assert.equal(cfg.asset.tagNumber, 'TAG-123'); }); test('buildDomainConfig prefers explicit assetUuid/assetTagCode when present', () => { const cfg = callBuildDomainConfig(makeUiConfig({ uuid: 'legacy-uuid', assetUuid: 'explicit-uuid', assetTagNumber: 'legacy-tag', assetTagCode: 'explicit-tag', })); assert.equal(cfg.asset.uuid, 'explicit-uuid'); assert.equal(cfg.asset.tagCode, 'explicit-tag'); }); test('buildDomainConfig builds explicit curveUnits and falls back for invalid flow unit', () => { const cfg = callBuildDomainConfig(makeUiConfig({ unit: 'not-a-unit', curvePressureUnit: 'mbar', curveFlowUnit: 'm3/h', curvePowerUnit: 'kW', curveControlUnit: '%', })); assert.equal(cfg.general.unit, 'm3/h'); assert.equal(cfg.asset.unit, 'm3/h'); assert.equal(cfg.asset.curveUnits.pressure, 'mbar'); assert.equal(cfg.asset.curveUnits.flow, 'm3/h'); assert.equal(cfg.asset.curveUnits.power, 'kW'); assert.equal(cfg.asset.curveUnits.control, '%'); }); test('buildDomainConfig stashes state config including logging + movement + time', () => { Machine._pendingExtras = null; const inst = Object.create(NodeClass.prototype); inst.buildDomainConfig(makeUiConfig({ enableLog: true, logLevel: 'warn', speed: 5, startup: 3 })); const extras = Machine._pendingExtras; assert.ok(extras, 'Machine._pendingExtras should be set by buildDomainConfig'); assert.equal(extras.stateConfig.general.logging.enabled, true); assert.equal(extras.stateConfig.general.logging.logLevel, 'warn'); assert.equal(extras.stateConfig.movement.speed, 5); assert.equal(extras.stateConfig.time.starting, 3); Machine._pendingExtras = null; });