Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resources): Verify Profiles #51

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions lib/resources/VerifyProfiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

var TelnyxResource = require('../TelnyxResource');
var utils = require('../utils');
var telnyxMethod = TelnyxResource.method;

function transformResponseData(response, telnyx) {
return utils.addResourceToResponseData(
response,
telnyx,
'verifyProfiles',
{
del: telnyxMethod({
method: 'DELETE',
path: '/{verify_profile_id}',
urlParams: ['verify_profile_id'],
paramsValues: [response.data.id],
paramsNames: ['id'],
}),

update: telnyxMethod({
method: 'PATCH',
path: '/{verify_profile_id}',
urlParams: ['verify_profile_id'],
paramsValues: [response.data.id],
paramsNames: ['id'],
}),
}
);
}

module.exports = require('../TelnyxResource').extend({
path: 'verify_profiles',

list: telnyxMethod({
method: 'GET',
methodType: 'list',

transformResponseData: transformResponseData,
}),

create: telnyxMethod({
method: 'POST',

transformResponseData: transformResponseData,
}),

retrieve: telnyxMethod({
method: 'GET',
path: '/{verify_profile_id}',
urlParams: ['verify_profile_id'],

transformResponseData: transformResponseData,
}),
});
1 change: 1 addition & 0 deletions lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var resources = {
ShortCodes: require('./resources/ShortCodes'),
MessagingProfileMetrics: require('./resources/MessagingProfileMetrics'),
TelephonyCredentials: require('./resources/TelephonyCredentials'),
VerifyProfiles: require('./resources/VerifyProfiles'),
};

Telnyx.TelnyxResource = require('./TelnyxResource');
Expand Down
92 changes: 92 additions & 0 deletions test/resources/VerifyProfiles.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict';


var utils = require('../../testUtils');
var telnyx = utils.getTelnyxMock();
var expect = require('chai').expect;

describe('VerifyProfiles Resource', function() {
function responseItemFn(profile) {
expect(profile).to.have.property('name');
expect(profile).to.have.property('id');
expect(profile).to.have.property('rcs_enabled');
expect(profile).to.have.property('messaging_enabled');
expect(profile).to.have.property('messaging_template');
expect(profile).to.have.property('default_timeout_secs');
expect(profile).to.include({record_type: 'verify_profile'});
}

describe('list', function() {
it('Sends the correct request', function() {
return telnyx.verifyProfiles.list()
.then((response) => {
responseItemFn(response.data[0]);
});
});
});

describe('retrieve', function() {
it('Sends the correct request', function() {
return telnyx.verifyProfiles.retrieve('123')
.then((response) => {
responseItemFn(response.data);
});
})
});

describe('create', function() {
it('Sends the correct request', function() {
return telnyx.verifyProfiles.create({name: 'test', messaging_enabled: true})
.then((response) => {
responseItemFn(response.data);
});
})
});

describe('del', function() {
it('Sends the correct request with create', function() {
return telnyx.verifyProfiles.create({name: 'test', messaging_enabled: true})
.then(function(response) {
const verifyProfile = response.data;
return verifyProfile.del()
.then((response) => {
responseItemFn(response.data);
});
})
});

it('Sends the correct request with retrieve', function() {
return telnyx.verifyProfiles.retrieve('123')
.then(function(response) {
const verifyProfile = response.data;
return verifyProfile.del()
.then((response) => {
responseItemFn(response.data);
});
})
});
});

describe('update', function() {
it('Sends the correct request with create', function() {
return telnyx.verifyProfiles.create({name: 'test', messaging_enabled: true})
.then(function(response) {
const verifyProfile = response.data;
return verifyProfile.update({name: 'test two', messaging_enabled: false})
.then((response) => {
responseItemFn(response.data);
});
})
});
it('Sends the correct request with retrieve', function() {
return telnyx.verifyProfiles.retrieve('123')
.then(function(response) {
const verifyProfile = response.data;
return verifyProfile.update({name: 'test two', messaging_enabled: false})
.then((response) => {
responseItemFn(response.data);
});
})
});
});
});