Skip to content

Commit

Permalink
add Messaging Profile Metrics Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Aug 7, 2020
1 parent eceafe0 commit cc1895e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/resources/MessagingProfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var ACTIONS = [
'phone_numbers',
'alphanumeric_sender_ids',
'short_codes',
'metrics'
];

function getSpec(messagingProfileId) {
Expand Down Expand Up @@ -98,5 +99,12 @@ module.exports = require('../TelnyxResource').extend({
path: '/{messagingProfileId}/alphanumeric_sender_ids',
urlParams: ['messagingProfileId'],
}),

retrieveMetrics: telnyxMethod({
method: 'GET',
path: '/{messagingProfileId}/metrics',
urlParams: ['messagingProfileId'],
methodType: 'retrieve',
}),
});

52 changes: 52 additions & 0 deletions test/resources/MessagingProfiles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,57 @@ describe('MessagingProfiles Resource', function() {
});
});
});

describe.skip('Metrics methods', function() {
function metricsResponseFn(response) {
expect(response.data[0]).to.have.property('inbound');
expect(response.data[0]).to.have.property('outbound');
expect(response.data[0]).to.have.property('phone_numbers');
expect(response.data[0]).to.have.property('messaging_profile_id');
expect(response.data[0]).to.include({record_type: 'messaging_profile_metrics'});
}

function metricsNestedResponseFn(response) {
expect(response.data).to.have.property('id');
expect(response.data).to.have.property('detailed');
expect(response.data).to.have.property('overview');
expect(response.data.overview).to.have.property('inbound');
expect(response.data.overview).to.have.property('outbound');
expect(response.data.overview).to.have.property('phone_numbers');
expect(response.data.overview).to.have.property('messaging_profile_id');
expect(response.data.overview).to.include({record_type: 'messaging_profile_metrics'});
}

describe('retrieveMetrics', function() {
it('Sends the correct request', function() {
return telnyx.messagingProfiles.retrieveMetrics('123')
.then(metricsResponseFn);
});

it('Sends the correct request [with specified auth]', function() {
return telnyx.messagingProfiles.retrieveMetrics('123', TEST_AUTH_KEY)
.then(metricsResponseFn);
});
});

describe.skip('nested metrics', function() {
it('Sends the correct request', function() {
return telnyx.messagingProfiles.create({name: 'Summer Campaign'})
.then(function(response) {
const mp = response.data;
return mp.metrics()
.then(metricsNestedResponseFn);
})
});
it('Sends the correct request [with retrieve]', function() {
return telnyx.messagingProfiles.retrie({name: 'Summer Campaign'})
.then(function(response) {
const mp = response.data;
return mp.metrics()
.then(metricsNestedResponseFn);
})
});
});
})
})
});
2 changes: 1 addition & 1 deletion test/resources/OtaUpdates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var expect = require('chai').expect;
var TEST_AUTH_KEY = utils.getUserTelnyxKey();

describe('OtaUpdates Resource', function() {
describe.skip('retrieve', function() {
describe('retrieve', function() {
function responseFn(response) {
expect(response.data).to.include.keys(['id', 'sim_card_id', 'status', 'settings']);
expect(response.data).to.include({
Expand Down

0 comments on commit cc1895e

Please sign in to comment.