// 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); });