2026-02-19 17:37:42 +01:00
|
|
|
const test = require('node:test');
|
|
|
|
|
const assert = require('node:assert/strict');
|
|
|
|
|
|
|
|
|
|
const NodeClass = require('../../src/nodeClass');
|
|
|
|
|
const { makeNodeStub } = require('../helpers/factories');
|
|
|
|
|
|
2026-05-10 22:23:43 +02:00
|
|
|
// Post-refactor: BaseNodeAdapter handles registration via _scheduleRegistration
|
|
|
|
|
// (was _registerChild). Topic moved from 'registerChild' to 'child.register'.
|
|
|
|
|
test('_scheduleRegistration emits delayed child.register message on output 2', () => {
|
2026-02-19 17:37:42 +01:00
|
|
|
const inst = Object.create(NodeClass.prototype);
|
|
|
|
|
const node = makeNodeStub();
|
|
|
|
|
|
|
|
|
|
inst.node = node;
|
2026-05-10 22:23:43 +02:00
|
|
|
inst.config = { functionality: { positionVsParent: 'downstream', distance: null } };
|
2026-02-19 17:37:42 +01:00
|
|
|
|
|
|
|
|
const originalSetTimeout = global.setTimeout;
|
|
|
|
|
const delays = [];
|
2026-05-10 22:23:43 +02:00
|
|
|
global.setTimeout = (fn, ms) => { delays.push(ms); fn(); return 1; };
|
2026-02-19 17:37:42 +01:00
|
|
|
|
|
|
|
|
try {
|
2026-05-10 22:23:43 +02:00
|
|
|
inst._scheduleRegistration();
|
2026-02-19 17:37:42 +01:00
|
|
|
} finally {
|
|
|
|
|
global.setTimeout = originalSetTimeout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(delays, [100]);
|
|
|
|
|
assert.equal(node._sent.length, 1);
|
|
|
|
|
assert.equal(Array.isArray(node._sent[0]), true);
|
2026-05-10 22:23:43 +02:00
|
|
|
assert.equal(node._sent[0][2].topic, 'child.register');
|
2026-02-19 17:37:42 +01:00
|
|
|
assert.equal(node._sent[0][2].payload, node.id);
|
|
|
|
|
assert.equal(node._sent[0][2].positionVsParent, 'downstream');
|
|
|
|
|
});
|