Skip to content

Commit

Permalink
Merge f80e09e into 873fcd4
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Dec 7, 2019
2 parents 873fcd4 + f80e09e commit 3e198a8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 50 deletions.
7 changes: 7 additions & 0 deletions examples/webhook-signing/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ app.post('/webhooks', bodyParser.json(), function(req, res) {

console.log('Success', event.data.id);

// inbound call control
if (event.data.event_type === 'call.initiated') {
const call = new telnyx.Call({call_control_id: event.data.payload.call_control_id});

call.answer();
}

// Event was 'constructed', so we can respond with a 200 OK
res.status(200).send('Signed Webhook Received: ' + event.data.id);
});
Expand Down
22 changes: 0 additions & 22 deletions lib/ResourceNamespace.js

This file was deleted.

4 changes: 2 additions & 2 deletions lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ Telnyx.prototype = {
},

_createEmptyConstructor: function(content) {
return function() {
return content;
return function(args) {
return Object.assign(content, args || {});
}
}
};
Expand Down
27 changes: 15 additions & 12 deletions test/resources/Calls.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ describe('Calls Resource', function() {
}
}


function responseFn(response) {
expect(response.data).to.include({result: 'ok'});
}
Expand All @@ -137,9 +136,15 @@ describe('Calls Resource', function() {
COMMANDS.forEach(function(command) {
describe(command, function() {
const camelCaseCommand = utils.snakeToCamelCase(command);
let telnyxInstance;

this.beforeEach(() => {
// make specs independent
telnyxInstance = require('../../testUtils').getTelnyxMock();
});

it('Sends the correct request', function() {
return telnyx.calls.create(callCreateData)
return telnyxInstance.calls.create(callCreateData)
.then(function(response) {
const call = response.data;
call[utils.snakeToCamelCase(command)](callCommandsData[command] || {})
Expand All @@ -150,7 +155,7 @@ describe('Calls Resource', function() {
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.calls.create(callCreateData)
return telnyxInstance.calls.create(callCreateData)
.then(function(response) {
const call = response.data;
call[utils.snakeToCamelCase(command)](callCommandsData[command] || {}, TEST_AUTH_KEY)
Expand All @@ -162,31 +167,29 @@ describe('Calls Resource', function() {
});

it('Sends the correct method request [with empty resource instance]', function() {
const call = new telnyx.Call();
call.call_control_id = '3fa85f55-5717-4562-b3fc-2c963f63vga6';
const call = new telnyxInstance.Call({call_control_id: '3fa85f55-5717-4562-b3fc-2c963f63vga6'});

call[utils.snakeToCamelCase(command)](callCommandsData[command] || {})
.then(responseFn);

return call[command](callCommandsData[command] || {})
call[utils.snakeToCamelCase(command)](callCommandsData[command] || {}, TEST_AUTH_KEY)
.then(responseFn);
});

it('Sends the correct method request [with empty resource instance and specified auth]', function() {
const call = new telnyx.Call();
call.call_control_id = '3fa85f55-5717-4562-b3fc-2c963f63vga6';
const call = new telnyxInstance.Call({call_control_id: '3fa85f55-5717-4562-b3fc-2c963f63vga6'});

call[utils.snakeToCamelCase(command)](callCommandsData[command] || {}, TEST_AUTH_KEY)
call[command](callCommandsData[command] || {}, TEST_AUTH_KEY)
.then(responseFn);

return call[command](callCommandsData[command] || {}, TEST_AUTH_KEY)
return call[command](callCommandsData[command] || {})
.then(responseFn);
});

if (camelCaseCommand !== command) {
describe(camelCaseCommand, function() {
it('Sends the correct request', function() {
return telnyx.calls.create(callCreateData)
return telnyxInstance.calls.create(callCreateData)
.then(function(response) {
const call = response.data;

Expand All @@ -195,7 +198,7 @@ describe('Calls Resource', function() {
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.calls.create(callCreateData)
return telnyxInstance.calls.create(callCreateData)
.then(function(response) {
const call = response.data;

Expand Down
17 changes: 11 additions & 6 deletions test/resources/Conferences.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ describe('Calls Resource', function() {

CONFERENCES.forEach(function(action) {
describe(action, function() {
let telnyxInstance;

this.beforeEach(() => {
// make specs independent
telnyxInstance = require('../../testUtils').getTelnyxMock();
});

it('Sends the correct request', function() {
return telnyx.conferences.create(conferenceCreateData)
return telnyxInstance.conferences.create(conferenceCreateData)
.then(function(response) {
const conference = response.data;
return conference[action](callConferencesData[action] || {})
.then(responseFn);
})
});
it('Sends the correct request [with specified auth]', function() {
return telnyx.conferences.create(conferenceCreateData)
return telnyxInstance.conferences.create(conferenceCreateData)
.then(function(response) {
const conference = response.data;
return conference[action](callConferencesData[action] || {}, TEST_AUTH_KEY)
Expand All @@ -86,15 +93,13 @@ describe('Calls Resource', function() {
});

it('Sends the correct request [with empty resource instance]', function() {
const conference = new telnyx.Conference();
conference.call_control_id = '891510ac-f3e4-11e8-af5b-de00688a4901';
const conference = new telnyxInstance.Conference({id: '891510ac-f3e4-11e8-af5b-de00688a4901'});

return conference[action](callConferencesData[action] || {})
.then(responseFn);
});
it('Sends the correct request [with empty resource instance and specified auth]', function() {
const conference = new telnyx.Conference();
conference.call_control_id = '891510ac-f3e4-11e8-af5b-de00688a4901';
const conference = new telnyxInstance.Conference({id: '891510ac-f3e4-11e8-af5b-de00688a4901'});

return conference[action](callConferencesData[action] || {}, TEST_AUTH_KEY)
.then(responseFn);
Expand Down
8 changes: 0 additions & 8 deletions testUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ require('mocha');
// Ensure we are using the 'as promised' libs before any tests are run:
require('chai').use(require('chai-as-promised'));

var ResourceNamespace = require('../lib/ResourceNamespace').ResourceNamespace;

var utils = module.exports = {

getUserTelnyxKey: function() {
Expand All @@ -32,12 +30,6 @@ var utils = module.exports = {
function makeInstanceSpyable(telnyxInstance, thisInstance) {
if (thisInstance instanceof telnyx.TelnyxResource) {
patchRequest(telnyxInstance, thisInstance);
} else if (thisInstance instanceof ResourceNamespace) {
var namespace = thisInstance;

for (var j in namespace) {
makeInstanceSpyable(telnyxInstance, namespace[j]);
}
}
}

Expand Down

0 comments on commit 3e198a8

Please sign in to comment.