-
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.
- Loading branch information
Showing
3 changed files
with
169 additions
and
0 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
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, | ||
'fqdnConnections', | ||
{ | ||
del: telnyxMethod({ | ||
method: 'DELETE', | ||
path: '/{fqdnConnectionId}', | ||
urlParams: ['fqdnConnectionId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
|
||
update: telnyxMethod({ | ||
method: 'PATCH', | ||
path: '/{fqdnConnectionId}', | ||
urlParams: ['fqdnConnectionId'], | ||
paramsValues: [response.data.id], | ||
paramsNames: ['id'], | ||
}), | ||
} | ||
); | ||
} | ||
|
||
module.exports = TelnyxResource.extend({ | ||
path: 'fqdn_connections', | ||
|
||
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,113 @@ | ||
'use strict'; | ||
|
||
var telnyx = require('../../testUtils').getTelnyxMock(); | ||
var expect = require('chai').expect; | ||
|
||
var TEST_AUTH_KEY = 'KEY187557EC22404DB39975C43ACE661A58_9QdDI7XD5bvyahtaWx1YQo'; | ||
|
||
describe('FqdnConnections Resource', function() { | ||
describe('retrieve', function() { | ||
function responseFn(response) { | ||
expect(response.data).to.include({id: '123'}); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.fqdnConnections.retrieve('123').then(responseFn); | ||
}) | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdnConnections.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_name'); | ||
expect(response.data).to.have.property('record_type'); | ||
expect(response.data).to.include({connection_name: 'Central BSD-1', record_type: 'fqdn_connection'}); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'}) | ||
.then(responseFn); | ||
}) | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'}, TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}); | ||
|
||
it('Sends the correct request [with specified auth in options]', function() { | ||
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'}, {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_name'); | ||
expect(response.data[0]).to.include({record_type: 'fqdn_connection'}); | ||
} | ||
|
||
it('Sends the correct request', function() { | ||
return telnyx.fqdnConnections.list() | ||
.then(responseFn); | ||
}); | ||
|
||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdnConnections.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_name'); | ||
expect(response.data).to.include({record_type: 'fqdn_connection'}); | ||
} | ||
} | ||
|
||
describe('del', function() { | ||
it('Sends the correct request', function() { | ||
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'}) | ||
.then(function(response) { | ||
const mp = response.data; | ||
return mp.del() | ||
.then(responseFn); | ||
}) | ||
}); | ||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdnConnections.retrieve('123') | ||
.then(function(response) { | ||
const mp = response.data; | ||
return mp.del(TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}) | ||
}); | ||
}); | ||
|
||
describe('update', function() { | ||
it('Sends the correct request', function() { | ||
return telnyx.fqdnConnections.create({connection_name: 'Central BSD-1'}) | ||
.then(function(response) { | ||
const mp = response.data; | ||
return mp.update({connection_name: 'Western BSD-2'}) | ||
.then(responseFn); | ||
}) | ||
}); | ||
it('Sends the correct request [with specified auth]', function() { | ||
return telnyx.fqdnConnections.retrieve('123') | ||
.then(function(response) { | ||
const mp = response.data; | ||
return mp.update({connection_name: 'Western BSD-2'}, TEST_AUTH_KEY) | ||
.then(responseFn); | ||
}) | ||
}); | ||
}); | ||
}) | ||
}); |