Some checks are pending
CI / verify (push) Waiting to run
New /provisionDect slash command manages DECT basestations and handsets for a store via a single card: multi-select checkbox list doubles as the display, MACs render as AA:BB:CC:DD:EE:FF, Add/Remove sit side-by-side per section, and every removal goes through an explicit confirm card. Handsets always auto-pair (no bind-to-basestation input) so they roam. /finalizeStore now idempotently creates the "Store XXXX" DECT network (DBS-210) with the per-store default access code, so new stores are DECT-ready the moment finalize completes. Location-scoped lookup (findDectNetworkInLocation) handles both the finalize idempotency check and the /provisionDect fallback for freshly-created empty networks. Non-critical: a store can still go live if the DECT step fails, and /provisionDect keeps a recovery "create network" prompt for legacy stores. Pure-logic helpers (generateDectAccessCode, MAC normalize/format/ display, dectNetworkName) are unit-tested via node:test. Co-authored-by: Cursor <cursoragent@cursor.com>
102 lines
3.4 KiB
JavaScript
102 lines
3.4 KiB
JavaScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
dectNetworkName,
|
|
displayMac,
|
|
formatMac,
|
|
generateDectAccessCode,
|
|
normalizeMac,
|
|
} from '../src/webex/dect.js';
|
|
|
|
// AE's access code convention: 4-digit stores use their own digits; anything
|
|
// shorter prefixes '8' and pads the rest to 3. Ports collabFinder's rule
|
|
// verbatim so cross-project behaviour stays in sync.
|
|
describe('generateDectAccessCode', () => {
|
|
it('uses the store number verbatim for 4-digit stores', () => {
|
|
assert.equal(generateDectAccessCode(1234), '1234');
|
|
assert.equal(generateDectAccessCode('0499'), '0499');
|
|
});
|
|
|
|
it('truncates 5+ digit stores to the first 4', () => {
|
|
assert.equal(generateDectAccessCode(12345), '1234');
|
|
});
|
|
|
|
it("prefixes '8' and pads for shorter stores", () => {
|
|
assert.equal(generateDectAccessCode(347), '8347');
|
|
assert.equal(generateDectAccessCode(67), '8067');
|
|
assert.equal(generateDectAccessCode(1), '8001');
|
|
});
|
|
|
|
it('strips non-digit characters from the input', () => {
|
|
assert.equal(generateDectAccessCode('4-9-9'), '8499');
|
|
assert.equal(generateDectAccessCode('Store 1234'), '1234');
|
|
});
|
|
});
|
|
|
|
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), '—');
|
|
});
|
|
});
|
|
|
|
describe('dectNetworkName', () => {
|
|
it('produces the canonical "Store XXXX" name (4-digit padding)', () => {
|
|
assert.equal(dectNetworkName(499), 'Store 0499');
|
|
assert.equal(dectNetworkName(1), 'Store 0001');
|
|
assert.equal(dectNetworkName(1234), 'Store 1234');
|
|
assert.equal(dectNetworkName('67'), 'Store 0067');
|
|
});
|
|
});
|