before functional changes by codex
This commit is contained in:
0
test/integration/.gitkeep
Normal file
0
test/integration/.gitkeep
Normal file
48
test/integration/examples-flows.integration.test.js
Normal file
48
test/integration/examples-flows.integration.test.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const EXAMPLES_DIR = path.resolve(__dirname, '../../examples');
|
||||
|
||||
function readFlow(file) {
|
||||
const full = path.join(EXAMPLES_DIR, file);
|
||||
const parsed = JSON.parse(fs.readFileSync(full, 'utf8'));
|
||||
assert.equal(Array.isArray(parsed), true);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function nodesByType(flow, type) {
|
||||
return flow.filter((n) => n && n.type === type);
|
||||
}
|
||||
|
||||
function injectByTopic(flow, topic) {
|
||||
return flow.filter((n) => n && n.type === 'inject' && n.topic === topic);
|
||||
}
|
||||
|
||||
test('examples package contains required files', () => {
|
||||
for (const name of ['README.md', 'basic.flow.json', 'integration.flow.json', 'edge.flow.json']) {
|
||||
assert.equal(fs.existsSync(path.join(EXAMPLES_DIR, name)), true, `${name} missing`);
|
||||
}
|
||||
});
|
||||
|
||||
test('basic flow has measurement node and baseline injects', () => {
|
||||
const flow = readFlow('basic.flow.json');
|
||||
assert.equal(nodesByType(flow, 'measurement').length >= 1, true);
|
||||
assert.equal(injectByTopic(flow, 'measurement').length >= 1, true);
|
||||
assert.equal(injectByTopic(flow, 'calibrate').length >= 1, true);
|
||||
});
|
||||
|
||||
test('integration flow has two measurement nodes and registerChild example', () => {
|
||||
const flow = readFlow('integration.flow.json');
|
||||
assert.equal(nodesByType(flow, 'measurement').length >= 2, true);
|
||||
assert.equal(injectByTopic(flow, 'registerChild').length >= 1, true);
|
||||
assert.equal(injectByTopic(flow, 'measurement').length >= 1, true);
|
||||
});
|
||||
|
||||
test('edge flow contains edge-driving injects', () => {
|
||||
const flow = readFlow('edge.flow.json');
|
||||
assert.equal(injectByTopic(flow, 'measurement').length >= 1, true);
|
||||
assert.equal(injectByTopic(flow, 'outlierDetection').length >= 1, true);
|
||||
assert.equal(injectByTopic(flow, 'doesNotExist').length >= 1, true);
|
||||
});
|
||||
37
test/integration/measurement-event.integration.test.js
Normal file
37
test/integration/measurement-event.integration.test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const { makeMeasurementInstance } = require('../helpers/factories');
|
||||
|
||||
test('updateOutputAbs emits measurement event with configured type/position', async () => {
|
||||
const m = makeMeasurementInstance({
|
||||
asset: {
|
||||
uuid: '',
|
||||
tagCode: '',
|
||||
tagNumber: 'PT-001',
|
||||
supplier: 'vendor',
|
||||
category: 'sensor',
|
||||
type: 'pressure',
|
||||
model: 'PT-1',
|
||||
unit: 'bar',
|
||||
},
|
||||
functionality: {
|
||||
positionVsParent: 'upstream',
|
||||
distance: undefined,
|
||||
},
|
||||
smoothing: {
|
||||
smoothWindow: 1,
|
||||
smoothMethod: 'none',
|
||||
},
|
||||
});
|
||||
|
||||
const event = await new Promise((resolve) => {
|
||||
m.measurements.emitter.once('pressure.measured.upstream', resolve);
|
||||
m.calculateInput(30);
|
||||
});
|
||||
|
||||
assert.equal(event.type, 'pressure');
|
||||
assert.equal(event.variant, 'measured');
|
||||
assert.equal(event.position, 'upstream');
|
||||
assert.equal(typeof event.value, 'number');
|
||||
});
|
||||
Reference in New Issue
Block a user