Fix add-phone handoff and SMS Bower rotation
This commit is contained in:
@@ -142,3 +142,54 @@ test('SMS Bower provider acquires number with getNumberV2, polls code, and updat
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
test('SMS Bower rotate cancels rejected number then immediately acquires the next number', async () => {
|
||||
const requests = [];
|
||||
const provider = api.createProvider({
|
||||
fetchImpl: async (url, options = {}) => {
|
||||
const parsed = new URL(url);
|
||||
const action = parsed.searchParams.get('action');
|
||||
requests.push({ url: parsed, options });
|
||||
if (action === 'setStatus') {
|
||||
return createTextResponse('ACCESS_CANCEL');
|
||||
}
|
||||
if (action === 'getNumberV2') {
|
||||
return createTextResponse({ activationId: 'next-activation', phoneNumber: '447700900456', activationCost: 0.22, countryCode: 16 });
|
||||
}
|
||||
throw new Error(`unexpected ${parsed.toString()}`);
|
||||
},
|
||||
sleepWithStop: async () => {},
|
||||
throwIfStopped: () => {},
|
||||
});
|
||||
|
||||
const state = {
|
||||
smsBowerApiKey: 'demo-key',
|
||||
smsBowerServiceCode: 'dr',
|
||||
smsBowerCountryId: 16,
|
||||
smsBowerCountryLabel: 'United Kingdom',
|
||||
smsBowerMinPrice: '0.1',
|
||||
smsBowerMaxPrice: '0.3',
|
||||
};
|
||||
|
||||
const rotated = await provider.rotateActivation(
|
||||
state,
|
||||
{ activationId: 'old-activation', phoneNumber: '447700900123', provider: 'sms-bower', countryId: 16 },
|
||||
{ releaseAction: 'cancel', blockedCountryIds: [] }
|
||||
);
|
||||
|
||||
assert.equal(rotated.currentTicketId, 'old-activation');
|
||||
assert.equal(rotated.nextActivation.activationId, 'next-activation');
|
||||
assert.equal(rotated.nextActivation.phoneNumber, '447700900456');
|
||||
assert.deepStrictEqual(
|
||||
requests.map((entry) => [
|
||||
entry.url.searchParams.get('action'),
|
||||
entry.url.searchParams.get('id'),
|
||||
entry.url.searchParams.get('status'),
|
||||
]),
|
||||
[
|
||||
['setStatus', 'old-activation', '8'],
|
||||
['getNumberV2', null, null],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user