collabSupport/tests/phoneDiscovery.test.js
jmcqueen f7953b8eb5 Add MPP desk phone diagnostics follow-up to /phonestatus via relay.
Wire CP-78xx probe discovery, relay phone-probe commands, and a chat follow-up message so store desk phones get registration, switch, and provisioning detail alongside DECT and WAN diagnostics.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 18:01:01 -04:00

103 lines
3.1 KiB
JavaScript

// Unit tests for services/phoneDiscovery.js
import test from 'node:test';
import assert from 'node:assert/strict';
import {
discoverDeskPhones,
isMppDeskPhone,
} from '../services/phoneDiscovery.js';
const phone = (attrs = {}) => ({
mac: 'f0:b2:e5:67:89:ab',
name: 'Register 1',
product: 'Cisco CP-7841',
ipAddress: '10.4.11.50',
meraki: {},
...attrs,
});
test('isMppDeskPhone: accepts CP-78xx products', () => {
assert.equal(isMppDeskPhone({ product: 'Cisco CP-7841' }), true);
assert.equal(isMppDeskPhone({ product: 'Cisco 7841', capabilities: ['xapi'] }), true);
assert.equal(isMppDeskPhone({ model: 'CP-8851' }), true);
assert.equal(isMppDeskPhone({ name: 'Store 00782 CP-7841', product: 'Cisco 7841' }), true);
});
test('isMppDeskPhone: rejects non-desk devices', () => {
assert.equal(isMppDeskPhone({ product: 'Cisco Webex Room Kit' }), false);
assert.equal(isMppDeskPhone({ product: 'DBS-210-3PC' }), false);
});
test('discoverDeskPhones: empty input', () => {
assert.deepEqual(discoverDeskPhones({}), {
phones: [],
warnings: [],
inventory: { webexDeviceCount: 0, mppSelected: 0, skipped: [] },
});
});
test('discoverDeskPhones: happy path with nested phones.data', () => {
const { phones, warnings } = discoverDeskPhones({
phones: {
status: 'success',
data: [phone({ product: 'Cisco 7841', meraki: { ip: '10.4.11.50' } })],
},
});
assert.equal(warnings.length, 0);
assert.equal(phones.length, 1);
assert.equal(phones[0].ip, '10.4.11.50');
assert.equal(phones[0].source, 'meraki');
assert.equal(phones[0].product, 'Cisco 7841');
});
test('discoverDeskPhones: prefers Meraki IP over Webex', () => {
const { phones } = discoverDeskPhones({
phones: { data: [phone({ ipAddress: '10.9.9.9', meraki: { ip: '10.4.11.50' } })] },
});
assert.equal(phones[0].ip, '10.4.11.50');
});
test('discoverDeskPhones: skips non-10.x', () => {
const { phones, warnings } = discoverDeskPhones({
phones: { data: [phone({ ipAddress: '192.168.1.10', meraki: {} })] },
});
assert.equal(phones.length, 0);
assert.match(warnings[0].reason, /10\.0\.0\.0\/8/);
});
test('discoverDeskPhones: skips non-MPP inventory', () => {
const { phones } = discoverDeskPhones({
phones: {
data: [phone({ product: 'Cisco Webex Desk Pro' })],
},
});
assert.equal(phones.length, 0);
});
test('discoverDeskPhones: uses Meraki MAC when Webex MAC is placeholder', () => {
const { phones, warnings } = discoverDeskPhones({
phones: {
data: [phone({
mac: '—',
meraki: { ip: '10.4.11.50', mac: 'f0:b2:e5:67:89:ab' },
})],
},
});
assert.equal(warnings.length, 0);
assert.equal(phones.length, 1);
assert.equal(phones[0].mac, 'f0:b2:e5:67:89:ab');
});
test('discoverDeskPhones: dedupes by IP', () => {
const { phones, warnings } = discoverDeskPhones({
phones: {
data: [
phone({ mac: 'f0:b2:e5:67:89:ab', meraki: { ip: '10.4.11.50' } }),
phone({ mac: 'aa:bb:cc:dd:ee:ff', meraki: { ip: '10.4.11.50' } }),
],
},
});
assert.equal(phones.length, 1);
assert.match(warnings[0].reason, /duplicate IP/i);
});