Files
generalFunctions/test/output-utils.test.js
znetsixe bc79de133e fix(influx): accept tagCode camelCase and emit positionVsParent tag
The asset config standardised on tagCode (camelCase) but the InfluxDB
tag emitter still read the lowercase tagcode, so any node saved through
the new editor silently emitted tags.tagcode: undefined. Read both
spellings so old + new configs both produce the tag.

Also surfaces functionality.positionVsParent as a tag so dashboards
can filter by upstream/downstream side.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-23 15:29:39 +02:00

44 lines
1.4 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const OutputUtils = require('../src/helper/outputUtils.js');
const config = {
functionality: { softwareType: 'measurement', role: 'sensor' },
general: { id: 'abc', unit: 'mbar' },
asset: {
uuid: 'u1',
tagCode: 't1',
geoLocation: { lat: 51.6, lon: 4.7 },
category: 'measurement',
type: 'pressure',
model: 'M1',
},
};
test('process format emits message with changed fields only', () => {
const out = new OutputUtils();
const first = out.formatMsg({ a: 1, b: 2 }, config, 'process');
assert.equal(first.topic, 'measurement_abc');
assert.deepEqual(first.payload, { a: 1, b: 2 });
const second = out.formatMsg({ a: 1, b: 2 }, config, 'process');
assert.equal(second, null);
const third = out.formatMsg({ a: 1, b: 3, c: { x: 1 } }, config, 'process');
assert.deepEqual(third.payload, { b: 3, c: JSON.stringify({ x: 1 }) });
});
test('influx format flattens tags and stringifies tag values', () => {
const out = new OutputUtils();
const msg = out.formatMsg({ value: 10 }, config, 'influxdb');
assert.equal(msg.topic, 'measurement_abc');
assert.equal(msg.payload.measurement, 'measurement_abc');
assert.equal(msg.payload.tags.geoLocation_lat, '51.6');
assert.equal(msg.payload.tags.geoLocation_lon, '4.7');
assert.equal(msg.payload.tags.tagcode, 't1');
assert.ok(msg.payload.timestamp instanceof Date);
});