From 582015bae092d79f3fb634c1853d9e08f7364999 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Wed, 8 Jul 2020 11:16:31 -0300 Subject: [PATCH 1/4] fix outdated specs --- test/resources/Messages.spec.js | 17 ++++++----------- test/resources/NumberOrders.spec.js | 10 ++++++---- test/resources/SimCards.spec.js | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) 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' }); } From e056b71d11b94a738f430b07994a69e82c187bb8 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Wed, 8 Jul 2020 11:20:37 -0300 Subject: [PATCH 2/4] update telnyx-mock target version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From ddb7e27137542f6bc85551e973fd2c7066c64f8a Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Wed, 8 Jul 2020 13:18:14 -0300 Subject: [PATCH 3/4] add Faxes resource --- lib/resources/Faxes.js | 53 +++++++++++++++++ lib/telnyx.js | 3 +- test/resources/Faxes.spec.js | 108 +++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 lib/resources/Faxes.js create mode 100644 test/resources/Faxes.spec.js 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..568dda3 --- /dev/null +++ b/test/resources/Faxes.spec.js @@ -0,0 +1,108 @@ +'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('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); + }); + }); + }); + }); +}); From b76a0cbc68a2fa83e87368ded4c4e20e6c2f41f2 Mon Sep 17 00:00:00 2001 From: Lucas Rosa Date: Wed, 8 Jul 2020 13:25:10 -0300 Subject: [PATCH 4/4] add fax send specs --- test/resources/Faxes.spec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/resources/Faxes.spec.js b/test/resources/Faxes.spec.js index 568dda3..853be5e 100644 --- a/test/resources/Faxes.spec.js +++ b/test/resources/Faxes.spec.js @@ -59,6 +59,32 @@ describe('Faxes Resource', function () { }); }); + 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');