Skip to content

Commit

Permalink
Merge ec0bf7a into 1f36a4f
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Nov 14, 2019
2 parents 1f36a4f + ec0bf7a commit 3f74a6d
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cache:
env:
global:
# If changing this number, please also look it at tests config.
- TELNYX_MOCK_VERSION=0.4.0
- TELNYX_MOCK_VERSION=0.5.0

before_install:
# Unpack and start telnyx-mock so that the test suite can talk to it
Expand Down
40 changes: 40 additions & 0 deletions lib/resources/PhoneNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

var TelnyxResource = require('../TelnyxResource');
var telnyxMethod = TelnyxResource.method;

module.exports = require('../TelnyxResource').extend({
path: 'phone_numbers',
includeBasic: ['list', 'update', 'del'],

nestedResources: {
Messaging: require('./PhoneNumbersMessaging'),
Voice: require('./PhoneNumbersVoice')
},

retrieveVoiceSettings: telnyxMethod({
method: 'GET',
path: '/{id}/voice',
urlParams: ['id'],
methodType: 'retrieve',
}),

updateVoiceSettings: telnyxMethod({
method: 'PATCH',
path: '/{id}/voice',
urlParams: ['id'],
}),

retrieveMessagingSettings: telnyxMethod({
method: 'GET',
path: '/{id}/messaging',
urlParams: ['id'],
methodType: 'retrieve',
}),

updateMessagingSettings: telnyxMethod({
method: 'PATCH',
path: '/{id}/messaging',
urlParams: ['id'],
}),
});
6 changes: 6 additions & 0 deletions lib/resources/PhoneNumbersMessaging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = require('../TelnyxResource').extend({
path: 'phone_numbers/messaging',
includeBasic: ['list'],
});
6 changes: 6 additions & 0 deletions lib/resources/PhoneNumbersVoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = require('../TelnyxResource').extend({
path: 'phone_numbers/voice',
includeBasic: ['list'],
});
1 change: 1 addition & 0 deletions lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var resources = {
MessagingShortCodes: require('./resources/MessagingShortCodes'),
NumberOrders: require('./resources/NumberOrders'),
NumberReservations: require('./resources/NumberReservations'),
PhoneNumbers: require('./resources/PhoneNumbers'),
Calls: require('./resources/Calls'),
Conferences: require('./resources/Conferences'),
CallEvents: require('./resources/CallEvents'),
Expand Down
4 changes: 2 additions & 2 deletions test/resources/MessagingPhoneNumbers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ describe('MessagingPhoneNumbers Resource', function() {
describe('update', function() {
it('Sends the correct request', function() {
return telnyx.messagingPhoneNumbers.update('123', {
organization_id: '3fa85f64-5717-4562-b331-2c963f66afa6'
messaging_product: 'P2P'
})
.then(function(response) {
expect(response.data).to.include({
id: '123',
organization_id: '3fa85f64-5717-4562-b331-2c963f66afa6',
messaging_product: 'P2P',
record_type: 'messaging_phone_number',
});
});
Expand Down
104 changes: 104 additions & 0 deletions test/resources/PhoneNumbers.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
'use strict';

var telnyx = require('../../testUtils').getTelnyxMock();
var expect = require('chai').expect;

var TEST_AUTH_KEY = 'KEY187557EC22404DB39975C43ACE661A58_9QdDI7XD5bvyahtaWx1YQo';

describe('PhoneNumbers Resource', function() {
describe('update', function() {
it('Sends the correct request', function() {
return telnyx.phoneNumbers.update('123', {status: 'active'})
.then(function(response) {
expect(response.data).to.include({id: '123', phone_number: '+19705555098', record_type: 'phone_number'});
})
});
});

describe('del', function() {
it('Sends the correct request', function() {
return telnyx.phoneNumbers.del('123')
.then(function(response) {
expect(response.data).to.include({id: '123', phone_number: '+19705555098', record_type: 'phone_number'});
});
});
});

describe('list', function() {
function responseFn(response) {
expect(response.data[0]).to.have.property('id');
expect(response.data[0]).to.have.property('phone_number');
expect(response.data[0]).to.include({record_type: 'phone_number'});
}

it('Sends the correct request', function() {
return telnyx.phoneNumbers.list()
.then(responseFn);
});

it('Sends the correct request [with specified auth]', function() {
return telnyx.phoneNumbers.list(TEST_AUTH_KEY)
.then(responseFn);
});
});

describe('Voice methods', function() {
function responseFn(response) {
expect(response.data).to.have.property('id');
expect(response.data).to.have.property('translated_number');
expect(response.data).to.have.property('connection_id');
expect(response.data).to.include({record_type: 'voice_settings'});
}

describe('retrieveVoiceSettings', function() {
it('Sends the correct request', function() {
return telnyx.phoneNumbers.retrieveVoiceSettings('123')
.then(responseFn);
});

it('Sends the correct request [with specified auth]', function() {
return telnyx.phoneNumbers.retrieveVoiceSettings('123', TEST_AUTH_KEY)
.then(responseFn);
});
});

describe('updateVoiceSettings', function() {
it('Sends the correct request', function() {
return telnyx.phoneNumbers.updateVoiceSettings('123', {
tech_prefix_enabled: true,
})
.then(responseFn);
});
});
});

describe('Messaging methods', function() {
function responseFn(response) {
expect(response.data).to.have.property('id');
expect(response.data).to.have.property('phone_number');
expect(response.data).to.have.property('messaging_profile_id');
expect(response.data).to.include({record_type: 'messaging_settings'});
}

describe('retrieveMessagingSettings', function() {
it('Sends the correct request', function() {
return telnyx.phoneNumbers.retrieveMessagingSettings('123')
.then(responseFn);
});

it('Sends the correct request [with specified auth]', function() {
return telnyx.phoneNumbers.retrieveMessagingSettings('123', TEST_AUTH_KEY)
.then(responseFn);
});
});

describe('updateMessagingSettings', function() {
it('Sends the correct request', function() {
return telnyx.phoneNumbers.updateMessagingSettings('123', {
messaging_product: 'P2P',
})
.then(responseFn);
});
});
});
});
29 changes: 29 additions & 0 deletions test/resources/PhoneNumbersMessaging.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var telnyx = require('../../testUtils').getTelnyxMock();
var expect = require('chai').expect;

var TEST_AUTH_KEY = 'KEY187557EC22404DB39975C43ACE661A58_9QdDI7XD5bvyahtaWx1YQo';

describe('Phone Numbers Messaging Resource', function() {
function responseFn(response) {
expect(response.data[0]).to.include({
record_type: 'messaging_settings',
});
expect(response.data[0]).to.have.property('id');
expect(response.data[0]).to.have.property('phone_number');
expect(response.data[0]).to.have.property('messaging_profile_id');
}

describe('list', function() {
it('Sends the correct request', function() {
return telnyx.phoneNumbers.messaging.list()
.then(responseFn)
});

it('Sends the correct request [with specified auth]', function() {
return telnyx.phoneNumbers.messaging.list(TEST_AUTH_KEY)
.then(responseFn)
});
});
});
29 changes: 29 additions & 0 deletions test/resources/PhoneNumbersVoice.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var telnyx = require('../../testUtils').getTelnyxMock();
var expect = require('chai').expect;

var TEST_AUTH_KEY = 'KEY187557EC22404DB39975C43ACE661A58_9QdDI7XD5bvyahtaWx1YQo';

describe('Phone Numbers Voice Resource', function() {
function responseFn(response) {
expect(response.data[0]).to.include({
record_type: 'voice_settings',
});
expect(response.data[0]).to.have.property('id');
expect(response.data[0]).to.have.property('translated_number');
expect(response.data[0]).to.have.property('connection_id');
}

describe('list', function() {
it('Sends the correct request', function() {
return telnyx.phoneNumbers.voice.list()
.then(responseFn)
});

it('Sends the correct request [with specified auth]', function() {
return telnyx.phoneNumbers.voice.list(TEST_AUTH_KEY)
.then(responseFn)
});
});
});

0 comments on commit 3f74a6d

Please sign in to comment.