diff --git a/.travis.yml b/.travis.yml index 0aa5f97..8136c0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/resources/PhoneNumbers.js b/lib/resources/PhoneNumbers.js new file mode 100644 index 0000000..5cd2875 --- /dev/null +++ b/lib/resources/PhoneNumbers.js @@ -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'], + }), +}); diff --git a/lib/resources/PhoneNumbersMessaging.js b/lib/resources/PhoneNumbersMessaging.js new file mode 100644 index 0000000..e66575c --- /dev/null +++ b/lib/resources/PhoneNumbersMessaging.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = require('../TelnyxResource').extend({ + path: 'phone_numbers/messaging', + includeBasic: ['list'], +}); diff --git a/lib/resources/PhoneNumbersVoice.js b/lib/resources/PhoneNumbersVoice.js new file mode 100644 index 0000000..3129b53 --- /dev/null +++ b/lib/resources/PhoneNumbersVoice.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = require('../TelnyxResource').extend({ + path: 'phone_numbers/voice', + includeBasic: ['list'], +}); diff --git a/lib/telnyx.js b/lib/telnyx.js index 575a586..8e7afa1 100644 --- a/lib/telnyx.js +++ b/lib/telnyx.js @@ -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'), diff --git a/test/resources/MessagingPhoneNumbers.spec.js b/test/resources/MessagingPhoneNumbers.spec.js index 4a369d9..2a64d0a 100644 --- a/test/resources/MessagingPhoneNumbers.spec.js +++ b/test/resources/MessagingPhoneNumbers.spec.js @@ -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', }); }); diff --git a/test/resources/PhoneNumbers.spec.js b/test/resources/PhoneNumbers.spec.js new file mode 100644 index 0000000..32fbbbb --- /dev/null +++ b/test/resources/PhoneNumbers.spec.js @@ -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); + }); + }); + }); +}); diff --git a/test/resources/PhoneNumbersMessaging.spec.js b/test/resources/PhoneNumbersMessaging.spec.js new file mode 100644 index 0000000..da5a514 --- /dev/null +++ b/test/resources/PhoneNumbersMessaging.spec.js @@ -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) + }); + }); +}); diff --git a/test/resources/PhoneNumbersVoice.spec.js b/test/resources/PhoneNumbersVoice.spec.js new file mode 100644 index 0000000..9727757 --- /dev/null +++ b/test/resources/PhoneNumbersVoice.spec.js @@ -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) + }); + }); +});