agent updates

This commit is contained in:
znetsixe
2026-02-12 10:14:56 +01:00
parent 105a3082ab
commit 1cfb36f604
22 changed files with 649 additions and 23 deletions

42
test/output-utils.test.js Normal file
View File

@@ -0,0 +1,42 @@
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, undefined);
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.ok(msg.payload.timestamp instanceof Date);
});