Skip to content

Commit

Permalink
Merge ac787a9 into eea89a7
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Jul 14, 2020
2 parents eea89a7 + ac787a9 commit bd6672e
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
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,
}),
});
1 change: 1 addition & 0 deletions lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var resources = {
NumberLookup: require('./resources/NumberLookup'),
Balance: require('./resources/Balance'),
Addresses: require('./resources/Addresses'),
Faxes: require('./resources/Faxes'),
};

Telnyx.TelnyxResource = require('./TelnyxResource');
Expand Down
124 changes: 124 additions & 0 deletions test/resources/Faxes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
'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('connection_id');
expect(response.data).to.have.property('media_url');
expect(response.data).to.have.property('to');
}

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('connection_id');
expect(response.data).to.have.property('media_url');
expect(response.data).to.have.property('to');
}

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('connection_id');
expect(response.data).to.have.property('media_url');
expect(response.data).to.have.property('to');
}

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('connection_id');
expect(response.data[0]).to.have.property('media_url');
expect(response.data[0]).to.have.property('to');
}

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('connection_id');
expect(response.data).to.have.property('media_url');
expect(response.data).to.have.property('to');
}
}

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 bd6672e

Please sign in to comment.