diff --git a/.travis.yml b/.travis.yml index a83fcc4..881f550 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.8.8 + - TELNYX_MOCK_VERSION=0.8.10 before_install: # Unpack and start telnyx-mock so that the test suite can talk to it diff --git a/lib/resources/Faxes.js b/lib/resources/Faxes.js new file mode 100644 index 0000000..0c84a66 --- /dev/null +++ b/lib/resources/Faxes.js @@ -0,0 +1,53 @@ +'use strict'; + +var TelnyxResource = require('../TelnyxResource'); +var utils = require('../utils'); +var telnyxMethod = TelnyxResource.method; + +function transformResponseData(response, telnyx) { + return utils.addResourceToResponseData( + response, + telnyx, + 'faxes', + { + del: telnyxMethod({ + method: 'DELETE', + path: '/{faxId}', + urlParams: ['faxId'], + paramsValues: [response.data.id], + paramsNames: ['id'], + }), + } + ); +} + +module.exports = TelnyxResource.extend({ + path: 'faxes', + + list: telnyxMethod({ + method: 'GET', + methodType: 'list', + + transformResponseData: transformResponseData, + }), + + create: telnyxMethod({ + method: 'POST', + + transformResponseData: transformResponseData, + }), + + send: telnyxMethod({ + method: 'POST', + + transformResponseData: transformResponseData, + }), + + retrieve: telnyxMethod({ + method: 'GET', + path: '/{id}', + urlParams: ['id'], + + transformResponseData: transformResponseData, + }), +}); diff --git a/lib/telnyx.js b/lib/telnyx.js index 3be3f92..f106d65 100644 --- a/lib/telnyx.js +++ b/lib/telnyx.js @@ -61,7 +61,8 @@ var resources = { Actions: require('./resources/Actions'), OutboundVoiceProfiles: require('./resources/Outbound'), CallControlApplications: require('./resources/CallControlApplications'), - PhoneNumbersInboundChannels: require('./resources/PhoneNumbersInboundChannels') + PhoneNumbersInboundChannels: require('./resources/PhoneNumbersInboundChannels'), + Faxes: require('./resources/Faxes'), }; Telnyx.TelnyxResource = require('./TelnyxResource'); diff --git a/test/resources/Faxes.spec.js b/test/resources/Faxes.spec.js new file mode 100644 index 0000000..853be5e --- /dev/null +++ b/test/resources/Faxes.spec.js @@ -0,0 +1,134 @@ +'use strict'; + +var utils = require('../../testUtils'); +var telnyx = utils.getTelnyxMock(); +var expect = require('chai').expect; + +var TEST_AUTH_KEY = utils.getUserTelnyxKey(); + +var faxCreateData = { + connection_id: 'c-1', + media_url: 'http://www.example.com/fax.pdf', + quality: 'high', + to: '+456', + from: '+123', +} + +describe('Faxes Resource', function () { + describe('retrieve', function () { + function responseFn(response) { + // expect(response.data).to.have.property('fax_id'); + expect(response.data).to.have.property('connection_id'); + expect(response.data).to.have.property('media_url'); + expect(response.data).to.have.property('to'); + // expect(response.data).to.include({record_type: 'fax'}); + } + + it('Sends the correct request', function () { + return telnyx.faxes.retrieve('123').then(responseFn); + }); + + it('Sends the correct request [with specified auth]', function () { + return telnyx.faxes.retrieve('123', TEST_AUTH_KEY).then(responseFn); + }); + }); + + describe('create', function () { + function responseFn(response) { + // expect(response.data).to.have.property('fax_id'); + expect(response.data).to.have.property('connection_id'); + expect(response.data).to.have.property('media_url'); + expect(response.data).to.have.property('to'); + // expect(response.data).to.include({record_type: 'fax'}); + } + + it('Sends the correct request', function () { + return telnyx.faxes.create(faxCreateData).then(responseFn); + }); + + it('Sends the correct request [with specified auth]', function () { + return telnyx.faxes + .create(faxCreateData, TEST_AUTH_KEY) + .then(responseFn); + }); + + it('Sends the correct request [with specified auth in options]', function () { + return telnyx.faxes + .create(faxCreateData, {api_key: TEST_AUTH_KEY}) + .then(responseFn); + }); + }); + + describe('send', function () { + function responseFn(response) { + // expect(response.data).to.have.property('fax_id'); + expect(response.data).to.have.property('connection_id'); + expect(response.data).to.have.property('media_url'); + expect(response.data).to.have.property('to'); + // expect(response.data).to.include({record_type: 'fax'}); + } + + it('Sends the correct request', function () { + return telnyx.faxes.send(faxCreateData).then(responseFn); + }); + + it('Sends the correct request [with specified auth]', function () { + return telnyx.faxes + .send(faxCreateData, TEST_AUTH_KEY) + .then(responseFn); + }); + + it('Sends the correct request [with specified auth in options]', function () { + return telnyx.faxes + .send(faxCreateData, {api_key: TEST_AUTH_KEY}) + .then(responseFn); + }); + }); + + describe('list', function () { + function responseFn(response) { + // expect(response.data[0]).to.have.property('fax_id'); + expect(response.data[0]).to.have.property('connection_id'); + expect(response.data[0]).to.have.property('media_url'); + expect(response.data[0]).to.have.property('to'); + // expect(response.data[0]).to.include({record_type: 'fax'}); + } + + it('Sends the correct request', function () { + return telnyx.faxes.list().then(responseFn); + }); + + it('Sends the correct request [with specified auth]', function () { + return telnyx.faxes.list(TEST_AUTH_KEY).then(responseFn); + }); + }); + + describe('Nested', function () { + function responseFn(response) { + if (response.data) { + // expect(response.data).to.have.property('fax_id'); + expect(response.data).to.have.property('connection_id'); + expect(response.data).to.have.property('media_url'); + expect(response.data).to.have.property('to'); + // expect(response.data).to.include({record_type: 'fax'}); + } + } + + describe('del', function () { + it('Sends the correct request', function () { + return telnyx.faxes + .create(faxCreateData) + .then(function (response) { + const fax = response.data; + return fax.del().then(responseFn); + }); + }); + it('Sends the correct request [with specified auth]', function () { + return telnyx.faxes.retrieve('123').then(function (response) { + const fax = response.data; + return fax.del(TEST_AUTH_KEY).then(responseFn); + }); + }); + }); + }); +}); diff --git a/test/resources/Messages.spec.js b/test/resources/Messages.spec.js index e9d4830..09bc021 100644 --- a/test/resources/Messages.spec.js +++ b/test/resources/Messages.spec.js @@ -32,10 +32,8 @@ describe('Messages Resource', function() { to: [{address: '+18665552367'}], }) .then(function(response) { - expect(response.data).to.include({ - text: 'Hello, World!', - from: '+18665552368', - }); + expect(response.data).to.include.keys(['from', 'text']); + expect(response.data.from).to.include.keys(['carrier', 'line_type', 'phone_number']); expect(response.data.to[0]).to.include({address: '+18665552367'}); }) }); @@ -47,10 +45,8 @@ describe('Messages Resource', function() { to: [{address: '+18665552367'}], }, TEST_AUTH_KEY) .then(function(response) { - expect(response.data).to.include({ - text: 'Hello, World!', - from: '+18665552368' - }); + expect(response.data).to.include.keys(['from', 'text']); + expect(response.data.from).to.include.keys(['carrier', 'line_type', 'phone_number']); expect(response.data.to[0]).to.include({address: '+18665552367'}); }) }); @@ -62,9 +58,8 @@ describe('Messages Resource', function() { to: [{address: '+18665552367'}], }, {api_key: TEST_AUTH_KEY}) .then(function(response) { - expect(response.data).to.include({ - text: 'Hello, World!', - from: '+18665552368'}); + expect(response.data).to.include.keys(['from', 'text']); + expect(response.data.from).to.include.keys(['carrier', 'line_type', 'phone_number']); expect(response.data.to[0]).to.include({address: '+18665552367'}); }) }); diff --git a/test/resources/NumberOrders.spec.js b/test/resources/NumberOrders.spec.js index 5d72379..d02b6b3 100644 --- a/test/resources/NumberOrders.spec.js +++ b/test/resources/NumberOrders.spec.js @@ -31,8 +31,8 @@ describe('NumberOrders Resource', function() { expect(response.data[0]).to.have.property('id'); expect(response.data[0]).to.have.property('status'); expect(response.data[0]).to.have.property('customer_reference'); - expect(response.data[0]).to.have.property('connection_id'); - expect(response.data[0]).to.have.property('messaging_profile_id'); + expect(response.data[0]).to.have.property('requirements_met'); + expect(response.data[0]).to.have.property('phone_numbers_count'); expect(response.data[0]).to.include({record_type: 'number_order'}); } @@ -63,14 +63,16 @@ describe('NumberOrders Resource', function() { describe('create', function() { function responseFn(response) { expect(response.data).to.include({ - connection_id: '442191469269222625', record_type: 'number_order', }); + expect(response.data).to.have.property('requirements_met'); + expect(response.data).to.have.property('phone_numbers_count'); } function responseFnNoBody(response) { expect(response.data).to.have.property('id'); - expect(response.data).to.have.property('connection_id'); + expect(response.data).to.have.property('requirements_met'); + expect(response.data).to.have.property('phone_numbers_count'); expect(response.data).to.include({record_type: 'number_order'}); } diff --git a/test/resources/SimCards.spec.js b/test/resources/SimCards.spec.js index ae31e5d..f680760 100644 --- a/test/resources/SimCards.spec.js +++ b/test/resources/SimCards.spec.js @@ -9,8 +9,8 @@ var TEST_AUTH_KEY = 'KEY187557EC22404DB39975C43ACE661A58_9QdDI7XD5bvyahtaWx1YQo' describe('SimCards Resource', function() { describe('retrieve', function() { function responseFn(response) { + expect(response.data).to.have.property('id'); expect(response.data).to.include({ - id: '123', record_type: 'sim_card' }); }