Skip to content

Commit

Permalink
fix: allow no filter when getting owned numbers, require filter when …
Browse files Browse the repository at this point in the history
…searching available numbers (#747)
  • Loading branch information
dragonmantank authored Nov 30, 2022
1 parent 7d9fc80 commit ac80247
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/numbers/__tests__/numbers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ describe('Numbers', () => {
expect(results.numbers[0].country).toEqual(resp.numbers[0].country)
})

test('can get all owned numbers with no filter', async () => {
const resp = {
count: 1,
numbers: [
{
country: 'GB',
msisdn: '447700900000',
moHttpUrl: 'https://example.com/webhooks/inbound-sms',
type: 'mobile-lvn',
features: ['VOICE', 'SMS', 'MMS'],
messagesCallbackType: 'app',
messagesCallbackValue:
'aaaaaaaa-bbbb-cccc-dddd-0123456789ab',
voiceCallbackType: 'app',
voiceCallbackValue: 'aaaaaaaa-bbbb-cccc-dddd-0123456789ab',
},
],
}

nock(BASE_URL)
.get(`/account/numbers`)
.query({ api_key: '12345', api_secret: 'ABCDE' })
.reply(200, resp)

const results = await client.getOwnedNumbers()
expect(results.count).toEqual(1)
expect(results.numbers.length).toEqual(1)
expect(results.numbers[0].country).toEqual(resp.numbers[0].country)
})

test('getAvailableNumbers()', async () => {
const resp = {
count: 1234,
Expand Down
6 changes: 5 additions & 1 deletion packages/numbers/lib/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Numbers extends Client {
}

public async getAvailableNumbers(
filter?: NumbersSearchFilter
filter: NumbersSearchFilter
): Promise<NumbersAvailableList> {
const mapping = {
search_pattern: 'searchPattern',
Expand Down Expand Up @@ -101,6 +101,10 @@ export class Numbers extends Client {
public async getOwnedNumbers(
filter?: NumbersOwnedFilter
): Promise<NumbersOwnedList> {
if (!filter) {
filter = {}
}

const mapping = {
application_id: 'applicationId',
has_application: 'hasApplication',
Expand Down

0 comments on commit ac80247

Please sign in to comment.