const OutputUtils = require('../src/helper/outputUtils'); describe('OutputUtils', () => { let outputUtils; let config; beforeEach(() => { outputUtils = new OutputUtils(); config = { general: { name: 'Pump-1', id: 'node-1', unit: 'm3/h', }, functionality: { softwareType: 'pump', role: 'test-role', }, asset: { supplier: 'EVOLV', type: 'sensor', }, output: { process: 'process', dbase: 'influxdb', }, }; }); it('keeps legacy process output by default', () => { const msg = outputUtils.formatMsg({ flow: 12.5 }, config, 'process'); expect(msg).toEqual({ topic: 'Pump-1', payload: { flow: 12.5 }, }); }); it('keeps legacy influxdb output by default', () => { const msg = outputUtils.formatMsg({ flow: 12.5 }, config, 'influxdb'); expect(msg.topic).toBe('Pump-1'); expect(msg.payload).toEqual(expect.objectContaining({ measurement: 'Pump-1', fields: { flow: 12.5 }, tags: expect.objectContaining({ id: 'node-1', name: 'Pump-1', softwareType: 'pump', }), })); }); it('supports config-driven json formatting on the process channel', () => { config.output.process = 'json'; const msg = outputUtils.formatMsg({ flow: 12.5 }, config, 'process'); expect(msg.topic).toBe('Pump-1'); expect(typeof msg.payload).toBe('string'); expect(msg.payload).toContain('"measurement":"Pump-1"'); expect(msg.payload).toContain('"flow":12.5'); }); it('supports config-driven csv formatting on the database channel', () => { config.output.dbase = 'csv'; const msg = outputUtils.formatMsg({ flow: 12.5 }, config, 'influxdb'); expect(msg.topic).toBe('Pump-1'); expect(typeof msg.payload).toBe('string'); expect(msg.payload).toContain('Pump-1'); expect(msg.payload).toContain('flow=12.5'); }); });