-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resources): Messaging Profile Metrics and Short Codes (#43)
* add Short Codes Resource * add Messaging Profile Metrics Resource * add Messaging Profile Metrics Methods
- Loading branch information
1 parent
5e686a9
commit e4097e3
Showing
8 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = require('../TelnyxResource').extend({ | ||
path: 'messaging_profile_metrics', | ||
includeBasic: ['list'], | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
var TelnyxResource = require('../TelnyxResource'); | ||
var utils = require('../utils'); | ||
var telnyxMethod = TelnyxResource.method; | ||
|
||
function transformResponseData(response, telnyx) { | ||
return utils.addResourceToResponseData( | ||
response, | ||
telnyx, | ||
'shortCodes', | ||
{ | ||
update: telnyxMethod({ | ||
method: 'PATCH', | ||
path: '/{shortCodeId}', | ||
urlParams: ['shortCodeId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
} | ||
); | ||
} | ||
|
||
module.exports = TelnyxResource.extend({ | ||
path: 'short_codes', | ||
|
||
list: telnyxMethod({ | ||
method: 'GET', | ||
methodType: 'list', | ||
}), | ||
|
||
retrieve: telnyxMethod({ | ||
method: 'GET', | ||
path: '/{id}', | ||
urlParams: ['id'], | ||
|
||
transformResponseData: transformResponseData, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
var utils = require('../../testUtils'); | ||
var telnyx = utils.getTelnyxMock(); | ||
var expect = require('chai').expect; | ||
|
||
var TEST_AUTH_KEY = utils.getUserTelnyxKey(); | ||
|
||
describe('MessagingProfileMetrics Resource', function() { | ||
describe('list', function() { | ||
function responseFn(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'}); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.messagingProfileMetrics.list() | ||
.then(responseFn); | ||
}); | ||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.messagingProfileMetrics.list(TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict'; | ||
|
||
var utils = require('../../testUtils'); | ||
var telnyx = utils.getTelnyxMock(); | ||
var expect = require('chai').expect; | ||
|
||
var TEST_AUTH_KEY = utils.getUserTelnyxKey(); | ||
|
||
describe('ShortCodes Resource', function() { | ||
describe('retrieve', function() { | ||
function responseFn(response) { | ||
expect(response.data).to.have.property('id'); | ||
expect(response.data).to.have.property('short_code'); | ||
expect(response.data).to.have.property('country_code'); | ||
expect(response.data).to.have.property('messaging_profile_id'); | ||
expect(response.data).to.include({record_type: 'short_code'}); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.shortCodes.retrieve('123').then(responseFn); | ||
}) | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.shortCodes.retrieve('123', TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
}); | ||
|
||
describe('list', function() { | ||
function responseFn(response) { | ||
expect(response.data[0]).to.have.property('id'); | ||
expect(response.data[0]).to.have.property('short_code'); | ||
expect(response.data[0]).to.have.property('country_code'); | ||
expect(response.data[0]).to.have.property('messaging_profile_id'); | ||
expect(response.data[0]).to.include({record_type: 'short_code'}); | ||
|
||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.shortCodes.list() | ||
.then(responseFn); | ||
}); | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.shortCodes.list(TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
}); | ||
|
||
describe('Nested', function() { | ||
function responseFn(response) { | ||
if (response.data) { | ||
expect(response.data).to.have.property('id'); | ||
expect(response.data).to.have.property('short_code'); | ||
expect(response.data).to.have.property('country_code'); | ||
expect(response.data).to.have.property('messaging_profile_id'); | ||
expect(response.data).to.include({record_type: 'short_code'}); | ||
} | ||
} | ||
|
||
describe('update', function() { | ||
it('Sends the correct request', function() { | ||
return telnyx.shortCodes.retrieve('123') | ||
.then(function(response) { | ||
const mp = response.data; | ||
return mp.update({messaging_profile_id: 'uuid'}) | ||
.then(responseFn); | ||
}) | ||
}); | ||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.shortCodes.retrieve('123') | ||
.then(function(response) { | ||
const mp = response.data; | ||
return mp.update({messaging_profile_id: 'uuid'}, TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}) | ||
}); | ||
}); | ||
}) | ||
}); |