collabSupport/tests/resetVpPin.reset.test.js
jmcqueen 2ec2b7a486 Add /resetvmpin and /resetvppin with confirmation cards for Webex PIN resets.
Chat-only commands reset voicemail mailbox and voice portal passcodes via telephony_config_write, with extension lookup and unit tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-31 16:34:09 -04:00

61 lines
1.8 KiB
JavaScript

// tests/resetVpPin.reset.test.js
import test from 'node:test';
import assert from 'node:assert/strict';
import { resetVoicePortalPin } from '../services/voicePin/resetVoicePortalPin.js';
test('resetVoicePortalPin PUTs passcode using location rules length', async () => {
const calls = [];
const webexClient = {
async request(method, endpoint, body) {
calls.push({ method, endpoint, body });
return {};
},
};
const pin = await resetVoicePortalPin('LOC123', {
passcodeRules: { length: { min: 4, max: 4 } },
voicePortal: { extension: '9000', raw: { name: 'Portal', extension: '9000' } },
webexClient,
});
assert.match(pin, /^\d{4}$/);
assert.equal(calls.length, 1);
assert.equal(calls[0].method, 'PUT');
assert.equal(calls[0].endpoint, 'telephony/config/locations/LOC123/voicePortal');
assert.deepEqual(calls[0].body.passcode, {
newPasscode: pin,
confirmPasscode: pin,
});
});
test('resetVoicePortalPin merges full portal object on partial PUT failure', async () => {
let putAttempts = 0;
const webexClient = {
async request(method, endpoint, body) {
if (method === 'PUT') {
putAttempts += 1;
if (putAttempts === 1) {
const err = new Error('partial rejected');
err.response = { status: 400 };
throw err;
}
return body;
}
return { name: 'Store Portal', extension: '9000', phoneNumber: '+15551234567' };
},
};
const pin = await resetVoicePortalPin('LOC123', {
passcodeRules: { length: { min: 6, max: 6 } },
voicePortal: {
extension: '9000',
raw: { name: 'Store Portal', extension: '9000', phoneNumber: '+15551234567' },
},
webexClient,
});
assert.match(pin, /^\d{6}$/);
assert.equal(putAttempts, 2);
});