-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
039f86c
commit 19f8f5f
Showing
3 changed files
with
172 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,55 @@ | ||
'use strict'; | ||
|
||
var TelnyxResource = require('../TelnyxResource'); | ||
var utils = require('../utils'); | ||
var telnyxMethod = TelnyxResource.method; | ||
|
||
function transformResponseData(response, telnyx) { | ||
return utils.addResourceToResponseData( | ||
response, | ||
telnyx, | ||
'simCardGroups', | ||
{ | ||
del: telnyxMethod({ | ||
method: 'DELETE', | ||
path: '/{simCardGroupId}', | ||
urlParams: ['simCardGroupId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
|
||
update: telnyxMethod({ | ||
method: 'PATCH', | ||
path: '/{simCardGroupId}', | ||
urlParams: ['simCardGroupId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
} | ||
); | ||
} | ||
|
||
module.exports = TelnyxResource.extend({ | ||
path: 'sim_card_groups', | ||
|
||
list: telnyxMethod({ | ||
method: 'GET', | ||
methodType: 'list', | ||
|
||
transformResponseData: transformResponseData, | ||
}), | ||
|
||
create: telnyxMethod({ | ||
method: 'POST', | ||
|
||
transformResponseData: transformResponseData, | ||
}), | ||
|
||
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,115 @@ | ||
'use strict'; | ||
|
||
var utils = require('../../testUtils'); | ||
var telnyx = utils.getTelnyxMock(); | ||
var expect = require('chai').expect; | ||
|
||
var TEST_AUTH_KEY = utils.getUserTelnyxKey(); | ||
|
||
describe('SimCardGroups Resource', function() { | ||
describe('retrieve', function() { | ||
function responseFn(response) { | ||
expect(response.data).to.include.keys(['id', 'name', 'data_enabled', 'data_limit', 'consumed_data']); | ||
expect(response.data).to.include({record_type: 'sim_card_group'}); | ||
expect(response.data.consumed_data).to.include.keys(['amount', 'unit']); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.simCardGroups.retrieve('123').then(responseFn); | ||
}) | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.simCardGroups.retrieve('123', TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
}); | ||
|
||
describe('create', function() { | ||
function responseFn(response) { | ||
expect(response.data).to.include.keys(['id', 'name', 'data_enabled', 'data_limit', 'consumed_data']); | ||
expect(response.data).to.include({record_type: 'sim_card_group'}); | ||
expect(response.data.consumed_data).to.include.keys(['amount', 'unit']); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.simCardGroups.create({name: 'My Custom Group'}) | ||
.then(responseFn); | ||
}) | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.simCardGroups.create({name: 'My Custom Group'}, TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
|
||
it('Sends the correct request [with specified auth in options]', function() { | ||
return telnyx.simCardGroups.create({name: 'My Custom Group'}, {api_key: TEST_AUTH_KEY}) | ||
.then(responseFn); | ||
}); | ||
}); | ||
|
||
describe('list', function() { | ||
function responseFn(response) { | ||
expect(response.data[0]).to.include.keys(['id', 'name', 'data_enabled', 'data_limit', 'consumed_data']); | ||
expect(response.data[0]).to.include({record_type: 'sim_card_group'}); | ||
expect(response.data[0].consumed_data).to.include.keys(['amount', 'unit']); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.simCardGroups.list() | ||
.then(responseFn); | ||
}); | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.simCardGroups.list(TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
}); | ||
|
||
describe('Nested', function() { | ||
function responseFn(response) { | ||
if (response.data) { | ||
expect(response.data).to.include.keys(['id', 'name', 'data_enabled', 'data_limit', 'consumed_data']); | ||
expect(response.data).to.include({record_type: 'sim_card_group'}); | ||
expect(response.data.consumed_data).to.include.keys(['amount', 'unit']); | ||
} | ||
} | ||
|
||
describe('del', function() { | ||
it('Sends the correct request', function() { | ||
return telnyx.simCardGroups.create({name: 'My Custom Group'}) | ||
.then(function(response) { | ||
const simCardGroup = response.data; | ||
return simCardGroup.del() | ||
.then(responseFn); | ||
}) | ||
}); | ||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.simCardGroups.retrieve('123') | ||
.then(function(response) { | ||
const simCardGroup = response.data; | ||
return simCardGroup.del(TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}) | ||
}); | ||
}); | ||
|
||
describe('update', function() { | ||
it('Sends the correct request', function() { | ||
return telnyx.simCardGroups.create({name: 'My Custom Group'}) | ||
.then(function(response) { | ||
const simCardGroup = response.data; | ||
return simCardGroup.update({name: 'My Custom Updated Group'}) | ||
.then(responseFn); | ||
}) | ||
}); | ||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.simCardGroups.retrieve('123') | ||
.then(function(response) { | ||
const simCardGroup = response.data; | ||
return simCardGroup.update({name: 'My Custom Updated Group'}, TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}) | ||
}); | ||
}); | ||
}) | ||
}); |