Skip to content

Commit

Permalink
add Faxes resource
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Jul 8, 2020
1 parent e056b71 commit ddb7e27
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 1 deletion.
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
108 changes: 108 additions & 0 deletions test/resources/Faxes.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
});

0 comments on commit ddb7e27

Please sign in to comment.