Skip to content

Commit

Permalink
feat(resources): Verifications (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa authored Dec 17, 2020
1 parent b111f82 commit 54a963b
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/resources/Verifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

var TelnyxResource = require('../TelnyxResource');

module.exports = TelnyxResource.extend({
path: 'verifications',

nestedResources: {
ByPhoneNumber: require('./VerificationsByPhoneNumber'),
},

create: TelnyxResource.method({
method: 'POST',
}),

retrieve: TelnyxResource.method({
method: 'GET',
path: '/{verification_id}',
urlParams: ['verification_id'],
}),
});
31 changes: 31 additions & 0 deletions lib/resources/VerificationsByPhoneNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

var TelnyxResource = require('../TelnyxResource');

module.exports = TelnyxResource.extend({
path: 'verifications/by_phone_number',

submit: TelnyxResource.method({
method: 'POST',
path: '/{phone_number}/actions/verify',
urlParams: ['phone_number'],
}),

create: TelnyxResource.method({
method: 'POST',
path: '/{phone_number}/actions/verify',
urlParams: ['phone_number'],
}),

verify: TelnyxResource.method({
method: 'POST',
path: '/{phone_number}/actions/verify',
urlParams: ['phone_number'],
}),

list: TelnyxResource.method({
method: 'GET',
path: '/{phone_number}',
urlParams: ['phone_number'],
}),
});
1 change: 1 addition & 0 deletions lib/telnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var resources = {
MessagingProfileMetrics: require('./resources/MessagingProfileMetrics'),
TelephonyCredentials: require('./resources/TelephonyCredentials'),
VerifyProfiles: require('./resources/VerifyProfiles'),
Verifications: require('./resources/Verifications'),
};

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


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

describe('Verifications Resource', function() {
function responseItemFn(verification) {
expect(verification).to.have.property('id');
expect(verification).to.have.property('type');
expect(verification).to.have.property('status');
expect(verification).to.have.property('phone_number');
expect(verification).to.have.property('timeout_secs');
expect(verification).to.include({record_type: 'verification'});
}
describe('retrieve', function() {
it('Sends the correct request', function() {
return telnyx.verifications.retrieve('123')
.then((response) => {
responseItemFn(response.data);
});
})
});

describe('create', function() {
it('Sends the correct request', function() {
return telnyx.verifications.create({
verify_profile_id: '12ade33a-21c0-473b-b055-b3c836e1c292',
phone_number: '+13035551234',
type: 'sms',
})
.then((response) => {
responseItemFn(response.data);
});
})
});
});
33 changes: 33 additions & 0 deletions test/resources/VerificationsByPhoneNumber.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

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

describe('VerificationsByPhoneNumbers Resource', function() {
function responseFn(response) {
expect(response.data[0]).to.have.property('id');
expect(response.data[0]).to.have.property('type');
expect(response.data[0]).to.have.property('status');
expect(response.data[0]).to.have.property('phone_number');
expect(response.data[0]).to.have.property('timeout_secs');
expect(response.data[0]).to.include({record_type: 'verification'});
}

describe('list', function() {
it('Sends the correct request', function() {
return telnyx.verifications.byPhoneNumber.list('+13035551234')
.then(responseFn)
});
});

describe('submit', function() {
it('Sends the correct request', function() {
return telnyx.verifications.byPhoneNumber.submit('+13035551234', {code: '17686'})
.then((response) => {
expect(response.data).to.have.property('phone_number');
expect(response.data).to.have.property('response_code');
});
})
});
});

0 comments on commit 54a963b

Please sign in to comment.