Files
measurement/test/edge/invalid-payload.edge.test.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

2026-02-19 17:37:21 +01:00
const test = require('node:test');
const assert = require('node:assert/strict');
const NodeClass = require('../../src/nodeClass');
const commands = require('../../src/commands');
const { createRegistry } = require('generalFunctions');
2026-02-19 17:37:21 +01:00
const { makeNodeStub, makeREDStub } = require('../helpers/factories');
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 = [];
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() {},
};
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();
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
});