import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { WIRED_PHONE_MODELS, filterWiredPhones, isSupportedWiredModel, } from '../src/webex/phones.js'; // Sanity check: the supported models list stays in sync with the two // models AE actually deploys. Add a case below when a new model lands. describe('WIRED_PHONE_MODELS', () => { it('includes both Cisco 7841 and 7821', () => { const values = WIRED_PHONE_MODELS.map((m) => m.value); assert.ok(values.includes('Cisco 7841'), '7841 missing'); assert.ok(values.includes('Cisco 7821'), '7821 missing'); }); it('7841 is first (used as the default in the add card)', () => { assert.equal(WIRED_PHONE_MODELS[0].value, 'Cisco 7841'); }); }); describe('isSupportedWiredModel', () => { it('accepts the exact strings in WIRED_PHONE_MODELS', () => { assert.equal(isSupportedWiredModel('Cisco 7841'), true); assert.equal(isSupportedWiredModel('Cisco 7821'), true); }); it('is case-sensitive so we always send Webex the canonical name', () => { assert.equal(isSupportedWiredModel('cisco 7841'), false); assert.equal(isSupportedWiredModel('CISCO 7841'), false); }); it('rejects unknown models', () => { assert.equal(isSupportedWiredModel('Cisco 8845'), false); assert.equal(isSupportedWiredModel(''), false); assert.equal(isSupportedWiredModel(undefined), false); }); }); describe('filterWiredPhones', () => { it('keeps 78xx MPP phones', () => { const items = [ { id: '1', product: 'Cisco 7841' }, { id: '2', product: 'Cisco 7821' }, ]; const kept = filterWiredPhones(items).map((d) => d.id); assert.deepEqual(kept, ['1', '2']); }); it('drops DECT devices by product name', () => { const items = [ { id: '1', product: 'Cisco 7841' }, { id: '2', product: 'DMS Cisco DBS210' }, { id: '3', product: 'DECT Handset' }, ]; const kept = filterWiredPhones(items).map((d) => d.id); assert.deepEqual(kept, ['1']); }); it('is case-insensitive on the DECT marker so future firmware names still match', () => { const items = [{ id: '1', product: 'cisco dbs-210' }]; assert.equal(filterWiredPhones(items).length, 0); }); it('falls back to `model` when `product` is missing', () => { // Some Webex endpoints report `model` instead of `product`; we // accept either so filterWiredPhones works against both shapes. const items = [{ id: '1', model: 'Cisco 7841' }]; assert.equal(filterWiredPhones(items).length, 1); }); it("drops entries with no model info (can't classify)", () => { const items = [{ id: '1' }, { id: '2', product: '' }]; assert.equal(filterWiredPhones(items).length, 0); }); it('accepts an empty array', () => { assert.deepEqual(filterWiredPhones([]), []); assert.deepEqual(filterWiredPhones(), []); }); });