2026-02-19 17:37:21 +01:00
|
|
|
const test = require('node:test');
|
|
|
|
|
const assert = require('node:assert/strict');
|
|
|
|
|
|
|
|
|
|
const NodeClass = require('../../src/nodeClass');
|
2026-05-10 20:39:54 +02:00
|
|
|
const commands = require('../../src/commands');
|
|
|
|
|
const { createRegistry } = require('generalFunctions');
|
2026-02-19 17:37:21 +01:00
|
|
|
const { makeNodeStub, makeREDStub } = require('../helpers/factories');
|
|
|
|
|
|
2026-05-10 20:39:54 +02:00
|
|
|
test('measurement topic accepts numeric strings and ignores non-numeric objects', async () => {
|
2026-02-19 17:37:21 +01:00
|
|
|
const inst = Object.create(NodeClass.prototype);
|
|
|
|
|
const node = makeNodeStub();
|
|
|
|
|
const calls = [];
|
2026-05-10 20:39:54 +02:00
|
|
|
const source = {
|
|
|
|
|
mode: 'analog',
|
|
|
|
|
logger: { warn: () => {}, info: () => {}, debug: () => {}, error: () => {} },
|
2026-02-19 17:37:21 +01:00
|
|
|
set inputValue(v) { calls.push(v); },
|
|
|
|
|
toggleSimulation() {},
|
|
|
|
|
toggleOutlierDetection() {},
|
|
|
|
|
calibrate() {},
|
|
|
|
|
};
|
|
|
|
|
|
2026-05-10 20:39:54 +02:00
|
|
|
inst.node = node;
|
|
|
|
|
inst.RED = makeREDStub();
|
|
|
|
|
inst.source = source;
|
|
|
|
|
inst._commands = createRegistry(commands, { logger: source.logger });
|
2026-02-19 17:37:21 +01:00
|
|
|
inst._attachInputHandler();
|
|
|
|
|
|
2026-05-10 20:39:54 +02:00
|
|
|
const onInput = node._handlers.input;
|
|
|
|
|
await onInput({ topic: 'measurement', payload: '42' }, () => {}, () => {});
|
|
|
|
|
await onInput({ topic: 'measurement', payload: { value: 42 } }, () => {}, () => {});
|
2026-02-19 17:37:21 +01:00
|
|
|
|
2026-02-23 13:17:03 +01:00
|
|
|
assert.deepEqual(calls, [42]);
|
2026-02-19 17:37:21 +01:00
|
|
|
});
|