-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resources): add Ips and Fqdns Resources (#25)
* add Ips Resource * add Fqdns Resource * target new telnyx-mock version
- Loading branch information
1 parent
406df79
commit 92b4ee0
Showing
7 changed files
with
353 additions
and
9 deletions.
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
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, | ||
'fqdns', | ||
{ | ||
del: telnyxMethod({ | ||
method: 'DELETE', | ||
path: '/{fqdnId}', | ||
urlParams: ['fqdnId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
|
||
update: telnyxMethod({ | ||
method: 'PATCH', | ||
path: '/{fqdnId}', | ||
urlParams: ['fqdnId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
} | ||
); | ||
} | ||
|
||
module.exports = TelnyxResource.extend({ | ||
path: 'fqdns', | ||
|
||
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
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, | ||
'ips', | ||
{ | ||
del: telnyxMethod({ | ||
method: 'DELETE', | ||
path: '/{ipId}', | ||
urlParams: ['ipId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
|
||
update: telnyxMethod({ | ||
method: 'PATCH', | ||
path: '/{ipId}', | ||
urlParams: ['ipId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
} | ||
); | ||
} | ||
|
||
module.exports = TelnyxResource.extend({ | ||
path: 'ips', | ||
|
||
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,116 @@ | ||
'use strict'; | ||
|
||
var telnyx = require('../../testUtils').getTelnyxMock(); | ||
var expect = require('chai').expect; | ||
|
||
var TEST_AUTH_KEY = 'KEY187557EC22404DB39975C43ACE661A58_9QdDI7XD5bvyahtaWx1YQo'; | ||
|
||
describe('Fqdns Resource', function() { | ||
describe('retrieve', function() { | ||
function responseFn(response) { | ||
expect(response.data).to.include({id: '123'}); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.fqdns.retrieve('123').then(responseFn); | ||
}) | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdns.retrieve('123', TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
}); | ||
|
||
describe('create', function() { | ||
function responseFn(response) { | ||
expect(response.data).to.have.property('id'); | ||
expect(response.data).to.have.property('connection_id'); | ||
expect(response.data).to.have.property('fqdn'); | ||
expect(response.data).to.have.property('record_type'); | ||
expect(response.data).to.include({connection_id: 'Central BSD-1', record_type: 'fqdn'}); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.fqdns.create({connection_id: 'Central BSD-1', fqdn: 'example.com'}) | ||
.then(responseFn); | ||
}) | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdns.create({connection_id: 'Central BSD-1', fqdn: 'example.com'}, TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
|
||
it('Sends the correct request [with specified auth in options]', function() { | ||
return telnyx.fqdns.create({connection_id: 'Central BSD-1', fqdn: 'example.com'}, {api_key: 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('connection_id'); | ||
expect(response.data).to.have.property('fqdn'); | ||
expect(response.data[0]).to.include({record_type: 'fqdn'}); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.fqdns.list() | ||
.then(responseFn); | ||
}); | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdns.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('connection_id'); | ||
expect(response.data).to.have.property('fqdn'); | ||
expect(response.data).to.include({record_type: 'fqdn'}); | ||
} | ||
} | ||
|
||
describe('del', function() { | ||
it('Sends the correct request', function() { | ||
return telnyx.fqdns.create({connection_id: 'Central BSD-1', fqdn: 'example.com'}) | ||
.then(function(response) { | ||
const fqdn = response.data; | ||
return fqdn.del() | ||
.then(responseFn); | ||
}) | ||
}); | ||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdns.retrieve('123') | ||
.then(function(response) { | ||
const fqdn = response.data; | ||
return fqdn.del(TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}) | ||
}); | ||
}); | ||
|
||
describe('update', function() { | ||
it('Sends the correct request', function() { | ||
return telnyx.fqdns.create({connection_id: 'Central BSD-1', fqdn: 'example.com'}) | ||
.then(function(response) { | ||
const fqdn = response.data; | ||
return fqdn.update({connection_id: 'Western BSD-2'}) | ||
.then(responseFn); | ||
}) | ||
}); | ||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdns.retrieve('123') | ||
.then(function(response) { | ||
const fqdn = response.data; | ||
return fqdn.update({connection_id: 'Western BSD-2'}, 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
Oops, something went wrong.