Skip to content

Commit

Permalink
Merge b76a0cb into b9e227f
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Jul 8, 2020
2 parents b9e227f + b76a0cb commit 46a4d56
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 18 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.8.8
- TELNYX_MOCK_VERSION=0.8.10

before_install:
# Unpack and start telnyx-mock so that the test suite can talk to it
Expand Down
53 changes: 53 additions & 0 deletions lib/resources/Faxes.js
Original file line number Diff line number Diff line change
@@ -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,
}),
});
3 changes: 2 additions & 1 deletion lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
134 changes: 134 additions & 0 deletions test/resources/Faxes.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
});
17 changes: 6 additions & 11 deletions test/resources/Messages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
})
});
Expand All @@ -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'});
})
});
Expand All @@ -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'});
})
});
Expand Down
10 changes: 6 additions & 4 deletions test/resources/NumberOrders.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
}

Expand Down Expand Up @@ -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'});
}

Expand Down
2 changes: 1 addition & 1 deletion test/resources/SimCards.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}
Expand Down

0 comments on commit 46a4d56

Please sign in to comment.