DECT basestations rely on multicast for handset discovery/registration.
When Meraki switches have IGMP snooping enabled without a querier —
or per-switch overrides that deviate from a DECT-safe policy — those
frames are pruned and DECT handsets silently fail to register.
- integrations/meraki/switches.js: getSwitchMulticastSettings,
setSwitchMulticastSettings, and pure summarizeMulticast verdict fn.
- services/phoneService.js: fires the multicast fetch as soon as the
network id is known, overlapping DECT enrichment; attaches
data.multicast summary to the collector output. Non-fatal on error.
- services/renderers/phoneStatusRenderer.js: emits a single warning
line inside the DECT Basestations section only when needsFix is
true, itemizing which parts deviate (default snoop, default flood,
N overrides).
- commands/igmpFix.js: frozen DECT_SAFE_MULTICAST_PAYLOAD constant
({snoop:false, flood:true, overrides:[]}), adaptive-card builder,
and confirm/cancel handlers.
- commands/phoneStatus.js: appends the adaptive card when needsFix
and the trigger came from chat (skipped on HTTP path).
- index.js: IGMP_FIX_ACTIONS set + dispatch branch mirroring the
HOST_ASSIGN pattern (one-shot pending lookup, censorActionCard,
domain call).
- utils/pendingIgmpFixes.js: 15-min TTL pending-card store.
- tests: 11 summarizer cases (all deviation permutations + malformed
input), 4 renderer cases (each warning-line shape + silence when
needsFix false or no DECT), and a frozen-constant regression guard
on the PUT payload. Full suite: 47/47 passing.
250 lines
9.5 KiB
JavaScript
250 lines
9.5 KiB
JavaScript
// Golden-ish tests for services/renderers/{phone,av}StatusRenderer.js
|
|
//
|
|
// True byte-for-byte golden strings aren't practical because both
|
|
// renderers call `simpleTimeAgo` (which uses `Date.now()`). Instead we
|
|
// assert on structural properties AND on the exact assembly of key
|
|
// lines — enough to catch a regression like "we lost the Meraki
|
|
// `[Meraki↗](url)` link" or "the header format changed" but robust to
|
|
// time-of-day drift.
|
|
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { renderPhoneStatusMarkdown } from '../services/renderers/phoneStatusRenderer.js';
|
|
import { renderAvStatusMarkdown } from '../services/renderers/avStatusRenderer.js';
|
|
|
|
// Timestamp exactly 3 hours in the past — makes `simpleTimeAgo`
|
|
// deterministic to "3 hours ago" for the duration of this test run.
|
|
const threeHrAgo = () => new Date(Date.now() - 3 * 60 * 60 * 1000).toISOString();
|
|
|
|
test('phone renderer: header and empty-store message', () => {
|
|
const md = renderPhoneStatusMarkdown({}, { storeNum: '782' });
|
|
assert.match(md, /^\*\*Phone Status - Store 782\*\*/);
|
|
assert.match(md, /No phones or DECT basestations found/);
|
|
});
|
|
|
|
test('phone renderer: full desk-phone entry preserves Meraki link', () => {
|
|
const data = {
|
|
phones: {
|
|
data: [{
|
|
displayName: 'PHONE 782-1',
|
|
status: 'connected',
|
|
lastSeen: threeHrAgo(),
|
|
firmware: '12.0.4',
|
|
serial: 'ABC12345',
|
|
meraki: {
|
|
switchName: 'STORE-782-SW1',
|
|
status: 'Online',
|
|
port: '17',
|
|
vlan: '20',
|
|
ip: '10.1.1.5',
|
|
lastSeen: threeHrAgo(),
|
|
clientUrl: 'https://n123.meraki.com/example/manage/clients/abc/overview',
|
|
usage: { sent: 1024, recv: 4096 },
|
|
},
|
|
}],
|
|
},
|
|
telephonyProfile: { timeZone: 'America/New_York' },
|
|
locationMainNumber: '+14125550100',
|
|
};
|
|
const md = renderPhoneStatusMarkdown(data, { storeNum: '782', footer: false });
|
|
// Header lines the poller cares about
|
|
assert.match(md, /\*\*Timezone:\*\* America\/New_York/);
|
|
assert.match(md, /\*\*PhoneNumber:\*\* \+14125550100/);
|
|
// Bold device name
|
|
assert.match(md, /\*\*PHONE 782-1\*\*/);
|
|
// Firmware / serial line
|
|
assert.match(md, /FW: 12\.0\.4 • Serial: ABC12345/);
|
|
// Meraki port info + link — the whole reason we ripped out the codeBlock
|
|
assert.match(md, /\*\*STORE-782-SW1\*\*/);
|
|
assert.match(md, /\[Meraki↗\]\(https:\/\/n123\.meraki\.com\/example\/manage\/clients\/abc\/overview\)/);
|
|
// Data usage
|
|
assert.match(md, /Data \(recent\): 1 KB sent \/ 4 KB recv/);
|
|
// No footer when opts.footer is false — Jira uses this mode
|
|
assert.doesNotMatch(md, /Last checked/);
|
|
});
|
|
|
|
test('phone renderer: footer appears when opts.footer=true (default) on non-empty data', () => {
|
|
// The empty-store branch legitimately returns early with no footer
|
|
// — that matches the chat handler's historical behavior. Feed a
|
|
// minimal populated fixture to exercise the footer path.
|
|
const data = {
|
|
phones: {
|
|
data: [{ displayName: 'X', status: 'connected', lastSeen: threeHrAgo() }],
|
|
},
|
|
};
|
|
const md = renderPhoneStatusMarkdown(data, { storeNum: '782' });
|
|
assert.match(md, /Last checked:/);
|
|
});
|
|
|
|
test('phone renderer: detailed mode reveals SIP details', () => {
|
|
const data = {
|
|
phones: {
|
|
data: [{
|
|
displayName: 'PHONE 782-2',
|
|
status: 'connected',
|
|
lastSeen: threeHrAgo(),
|
|
primarySipUrl: 'sip:782-2@aeo2go.webex.com',
|
|
sipUrls: ['sip:a@x', 'sip:b@x', 'sip:c@x'],
|
|
}],
|
|
},
|
|
};
|
|
const compact = renderPhoneStatusMarkdown(data, { storeNum: '782', detailed: false, footer: false });
|
|
const detailed = renderPhoneStatusMarkdown(data, { storeNum: '782', detailed: true, footer: false });
|
|
assert.doesNotMatch(compact, /SIP: sip:782-2/);
|
|
assert.match(detailed, /SIP: sip:782-2@aeo2go\.webex\.com/);
|
|
assert.match(detailed, /Alt SIPs: sip:a@x, sip:b@x…/);
|
|
});
|
|
|
|
// ─────────────────────────────────────────────────────────────
|
|
// IGMP snooping / DECT-safe multicast warning line
|
|
// ─────────────────────────────────────────────────────────────
|
|
|
|
test('phone renderer: multicast warning line includes every deviation kind', () => {
|
|
const data = {
|
|
dectBasestations: [
|
|
{ mac: 'aa:bb:cc:dd:ee:ff', meraki: { status: 'Online' } },
|
|
],
|
|
dectHandsets: [],
|
|
multicast: {
|
|
needsFix: true,
|
|
defaultSnoopOn: true,
|
|
defaultFloodOff: true,
|
|
deviatingOverrides: [{}, {}],
|
|
},
|
|
};
|
|
const md = renderPhoneStatusMarkdown(data, { storeNum: '782', footer: false });
|
|
assert.match(md, /\*\*Multicast:\*\* ⚠️/);
|
|
assert.match(md, /IGMP snoop=ON default/);
|
|
assert.match(md, /flood-unknown=OFF default/);
|
|
assert.match(md, /2 switch override\(s\) deviate/);
|
|
assert.match(md, /may disrupt DECT/);
|
|
});
|
|
|
|
test('phone renderer: multicast line names only the snoop deviation when that is the only problem', () => {
|
|
const data = {
|
|
dectBasestations: [
|
|
{ mac: 'aa:bb:cc:dd:ee:ff', meraki: { status: 'Online' } },
|
|
],
|
|
dectHandsets: [],
|
|
multicast: {
|
|
needsFix: true,
|
|
defaultSnoopOn: true,
|
|
defaultFloodOff: false,
|
|
deviatingOverrides: [],
|
|
},
|
|
};
|
|
const md = renderPhoneStatusMarkdown(data, { storeNum: '782', footer: false });
|
|
assert.match(md, /\*\*Multicast:\*\* ⚠️ IGMP snoop=ON default — may disrupt DECT/);
|
|
assert.doesNotMatch(md, /flood-unknown/);
|
|
assert.doesNotMatch(md, /switch override/);
|
|
});
|
|
|
|
test('phone renderer: multicast line is ABSENT when needsFix is false', () => {
|
|
const data = {
|
|
dectBasestations: [
|
|
{ mac: 'aa:bb:cc:dd:ee:ff', meraki: { status: 'Online' } },
|
|
],
|
|
dectHandsets: [],
|
|
multicast: {
|
|
needsFix: false,
|
|
defaultSnoopOn: false,
|
|
defaultFloodOff: false,
|
|
deviatingOverrides: [],
|
|
},
|
|
};
|
|
const md = renderPhoneStatusMarkdown(data, { storeNum: '782', footer: false });
|
|
assert.doesNotMatch(md, /\*\*Multicast:\*\*/);
|
|
});
|
|
|
|
test('phone renderer: multicast line is ABSENT when there are no DECT basestations', () => {
|
|
// Even if needsFix is true, the warning lives INSIDE the DECT section
|
|
// which itself is gated on dectBasestations.length > 0. Stores with
|
|
// no DECT get no multicast noise — it's simply not their problem.
|
|
const data = {
|
|
phones: {
|
|
data: [{ displayName: 'DESK', status: 'connected', lastSeen: threeHrAgo() }],
|
|
},
|
|
dectBasestations: [],
|
|
multicast: {
|
|
needsFix: true,
|
|
defaultSnoopOn: true,
|
|
defaultFloodOff: true,
|
|
deviatingOverrides: [{}],
|
|
},
|
|
};
|
|
const md = renderPhoneStatusMarkdown(data, { storeNum: '782', footer: false });
|
|
assert.doesNotMatch(md, /\*\*Multicast:\*\*/);
|
|
});
|
|
|
|
// ─────────────────────────────────────────────────────────────
|
|
|
|
test('av renderer: header always says (Mode: detailed)', () => {
|
|
const md = renderAvStatusMarkdown({}, { storeNum: '782', footer: false });
|
|
assert.match(md, /^\*\*Device Status - Store 782\*\* \(Mode: detailed\)/);
|
|
});
|
|
|
|
test('av renderer: MDM entry with Meraki wired client preserves link', () => {
|
|
const data = {
|
|
mdm: {
|
|
data: [{
|
|
friendlyName: 'STORE-782-KIOSK-1',
|
|
lastSeen: threeHrAgo(),
|
|
meraki: {
|
|
deviceName: 'STORE-782-SW2',
|
|
recentDeviceConnection: 'Wired',
|
|
status: 'Online',
|
|
clientStatus: 'Online',
|
|
port: '4',
|
|
vlan: '30',
|
|
ip: '10.1.2.20',
|
|
mac: 'aa:bb:cc:dd:ee:ff',
|
|
lastSeen: threeHrAgo(),
|
|
clientUrl: 'https://n123.meraki.com/example/manage/clients/xyz/overview',
|
|
},
|
|
}],
|
|
},
|
|
};
|
|
const md = renderAvStatusMarkdown(data, { storeNum: '782', footer: false });
|
|
assert.match(md, /\*\*STORE-782-KIOSK-1\*\*/);
|
|
assert.match(md, /\*\*STORE-782-SW2 \(Wired - Online\)\*\*/);
|
|
assert.match(md, /\[Meraki↗\]\(https:\/\/n123\.meraki\.com\/example\/manage\/clients\/xyz\/overview\)/);
|
|
// Port line with double-arrow indent
|
|
assert.match(md, / → → Port: \*\*4\*\*/);
|
|
});
|
|
|
|
test('av renderer: absent MDM devices prints friendly message', () => {
|
|
const md = renderAvStatusMarkdown({ mdm: { data: [] } }, { storeNum: '782', footer: false });
|
|
assert.match(md, /No MDM devices found for this store/);
|
|
});
|
|
|
|
test('av renderer: Atlas AMP with vitals renders temps + fan + amps', () => {
|
|
const data = {
|
|
mdm: { data: [] },
|
|
atlas: {
|
|
data: [{
|
|
name: 'US000782AMP',
|
|
status: 'online',
|
|
last_seen_at: new Date(Date.now() - 5 * 60 * 1000).toISOString(),
|
|
model: { name: 'Atlas-4M' },
|
|
firmware: { version: '1.9.3' },
|
|
sn: 'SN-782-AMP',
|
|
state: {
|
|
voltageMonitor: '120.4',
|
|
faultStatus: 0,
|
|
tempCpu: '40', tempPsu: '35', tempIo: '38',
|
|
fanSpeed: 45.7,
|
|
ampStatus_1: 'Active',
|
|
ampStatus_2: 'Ready',
|
|
IpAddress: '10.1.9.9',
|
|
},
|
|
}],
|
|
},
|
|
};
|
|
const md = renderAvStatusMarkdown(data, { storeNum: '782', footer: false });
|
|
assert.match(md, /\*\*Atlas Devices:\*\*/);
|
|
assert.match(md, /\*\*US000782AMP\*\* \(online\)/);
|
|
assert.match(md, /Atlas-4M • FW 1\.9\.3 • SN SN-782-AMP • IP 10\.1\.9\.9/);
|
|
assert.match(md, /CPU: 104°F • PSU: 95°F • Io: 100°F • Voltage: 120\.4V • Fan: 46%/);
|
|
assert.match(md, /Amps: Amp1: Active, Amp2: Ready/);
|
|
});
|