Some checks failed
CI / verify (push) Has been cancelled
New /provisionPhone <storeNumber> command manages the store user's wired desk phones via the same card pattern as /provisionDect: multi-select checkbox list that doubles as the display, MACs render as AA:BB:CC:DD:EE:FF, model dropdown for add (defaults to 7841), side-by-side Add / Remove-checked actions, and every removal goes through an explicit confirm card. Adds are idempotent (MACs already registered are skipped) and bulk MAC input is supported. DECT handsets are filtered out of the display so /provisionPhone and /provisionDect coexist cleanly on the same store user without overlapping responsibilities. Refactors: - Extract MAC helpers (normalize/format/display) to src/utils/mac.js so both DECT and wired-phone flows share one implementation. dect.js re-exports for backward compat with existing consumers. - Add parseEmailArg helper; migrate /userInfo to use it. Tests: pure-logic coverage for WIRED_PHONE_MODELS, isSupportedWiredModel, filterWiredPhones (DECT/model filter), and parseEmailArg. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
2 KiB
JavaScript
62 lines
2 KiB
JavaScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { displayMac, formatMac, normalizeMac } from '../src/utils/mac.js';
|
|
|
|
describe('normalizeMac', () => {
|
|
it('accepts colon-separated MACs', () => {
|
|
assert.equal(normalizeMac('AA:BB:CC:DD:EE:FF'), 'AABBCCDDEEFF');
|
|
});
|
|
|
|
it('accepts hyphen-separated MACs', () => {
|
|
assert.equal(normalizeMac('aa-bb-cc-dd-ee-ff'), 'AABBCCDDEEFF');
|
|
});
|
|
|
|
it('accepts unseparated MACs and case-normalizes', () => {
|
|
assert.equal(normalizeMac('aabbccddeeff'), 'AABBCCDDEEFF');
|
|
});
|
|
|
|
it('rejects too-short strings', () => {
|
|
assert.equal(normalizeMac('AA:BB:CC'), null);
|
|
});
|
|
|
|
it('rejects too-long strings', () => {
|
|
assert.equal(normalizeMac('AA:BB:CC:DD:EE:FF:11'), null);
|
|
});
|
|
|
|
it('rejects non-hex characters', () => {
|
|
// "Z" is not hex; after stripping we're left with 10 chars, not 12.
|
|
assert.equal(normalizeMac('AA:BB:CC:ZZ:EE:FF'), null);
|
|
});
|
|
|
|
it('returns null for missing input', () => {
|
|
assert.equal(normalizeMac(''), null);
|
|
assert.equal(normalizeMac(null), null);
|
|
assert.equal(normalizeMac(undefined), null);
|
|
});
|
|
});
|
|
|
|
describe('formatMac', () => {
|
|
it('inserts colons every two chars', () => {
|
|
assert.equal(formatMac('AABBCCDDEEFF'), 'AA:BB:CC:DD:EE:FF');
|
|
});
|
|
});
|
|
|
|
describe('displayMac', () => {
|
|
it('formats unseparated MACs (the Webex list-endpoint default)', () => {
|
|
assert.equal(displayMac('aabbccddeeff'), 'AA:BB:CC:DD:EE:FF');
|
|
});
|
|
|
|
it('re-formats already-separated MACs consistently', () => {
|
|
assert.equal(displayMac('aa-bb-cc-dd-ee-ff'), 'AA:BB:CC:DD:EE:FF');
|
|
});
|
|
|
|
it('passes unrecognised input through instead of throwing', () => {
|
|
assert.equal(displayMac('not-a-mac'), 'not-a-mac');
|
|
});
|
|
|
|
it('renders an em-dash for missing values', () => {
|
|
assert.equal(displayMac(null), '—');
|
|
assert.equal(displayMac(undefined), '—');
|
|
});
|
|
});
|