support for VoipCarriers that are customer PBXs

This commit is contained in:
Dave Horton
2020-02-08 10:39:17 -05:00
parent 1c9afcdf59
commit 9783afcff5
12 changed files with 271 additions and 799 deletions
+2 -13
View File
@@ -38,9 +38,6 @@ test('account tests', async(t) => {
method: 'get',
username: 'foo',
password: 'abr'
},
error_hook: {
url: 'http://example.com/error'
}
}
});
@@ -54,11 +51,9 @@ test('account tests', async(t) => {
});
let regHook = result[0].registration_hook;
let devHook = result[0].device_calling_hook;
let errHook = result[0].error_hook;
t.ok(result.length === 1 &&
Object.keys(regHook).length == 5 &&
Object.keys(devHook).length === 5 &&
Object.keys(errHook).length === 5, 'successfully queried all accounts');
Object.keys(devHook).length === 5, 'successfully queried all accounts');
/* query one accounts */
result = await request.get(`/Accounts/${sid}`, {
@@ -66,7 +61,6 @@ test('account tests', async(t) => {
json: true,
});
t.ok(result.name === 'daveh' , 'successfully retrieved account by sid');
const error_hook_sid = result.error_hook.webhook_sid;
/* update accounts */
result = await request.put(`/Accounts/${sid}`, {
@@ -78,10 +72,6 @@ test('account tests', async(t) => {
registration_hook: {
url: 'http://example.com/reg2',
method: 'get'
},
error_hook: {
webhook_sid: error_hook_sid,
method: 'post'
}
}
});
@@ -93,8 +83,7 @@ test('account tests', async(t) => {
});
//console.log(`retrieved account after update: ${JSON.stringify(result)}`);
t.ok(result.device_calling_hook === null &&
Object.keys(result.registration_hook).length === 5 &&
Object.keys(result.error_hook).length === 5, 'successfully removed a hook from account');
Object.keys(result.registration_hook).length === 5, 'successfully removed a hook from account');
/* assign phone number to account */
result = await request.put(`/PhoneNumbers/${phone_number_sid}`, {
+19
View File
@@ -48,6 +48,24 @@ async function createAccount(request, service_provider_sid, name = 'daveh') {
return result.sid;
}
async function createApplication(request, account_sid, name = 'daveh') {
const result = await request.post('/Applications', {
auth: authAdmin,
json: true,
body: {
name,
account_sid,
call_hook: {
url: 'http://example.com'
},
call_status_hook: {
url: 'http://example.com'
}
}
});
return result.sid;
}
async function deleteObjectBySid(request, path, sid) {
const result = await request.delete(`${path}/${sid}`, {
auth: authAdmin,
@@ -60,5 +78,6 @@ module.exports = {
createVoipCarrier,
createPhoneNumber,
createAccount,
createApplication,
deleteObjectBySid
};
+91 -1
View File
@@ -4,6 +4,7 @@ const authAdmin = {bearer: ADMIN_TOKEN};
const request = require('request-promise-native').defaults({
baseUrl: 'http://127.0.0.1:3000/v1'
});
const {createServiceProvider, createAccount, createApplication, deleteObjectBySid} = require('./utils');
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
@@ -25,7 +26,7 @@ test('voip carrier tests', async(t) => {
}
});
t.ok(result.statusCode === 201, 'successfully created voip carrier');
const sid = result.body.sid;
sid = result.body.sid;
/* query all voip carriers */
result = await request.get('/VoipCarriers', {
@@ -99,6 +100,95 @@ test('voip carrier tests', async(t) => {
//console.log(`result: ${JSON.stringify(result)}`);
t.ok(result.statusCode === 204, 'successfully deleted voip carrier');
/* create voipd carrier that is a customer PBX */
const service_provider_sid = await createServiceProvider(request);
const account_sid = await createAccount(request, service_provider_sid);
const account_sid2 = await createAccount(request, service_provider_sid, 'another');
const application_sid = await createApplication(request, account_sid);
result = await request.post('/VoipCarriers', {
resolveWithFullResponse: true,
simple: false,
auth: authAdmin,
json: true,
body: {
name: 'daveh',
account_sid: 'xxxx'
}
});
t.ok(result.statusCode === 400 && result.body.msg === 'unknown account_sid', 'fails to create voip_carrier with unknown account_sid');
result = await request.post('/VoipCarriers', {
resolveWithFullResponse: true,
simple: false,
auth: authAdmin,
json: true,
body: {
name: 'daveh',
application_sid
}
});
t.ok(result.statusCode === 400 && result.body.msg === 'account_sid missing', 'fails to create voip_carrier with missing account_sid');
result = await request.post('/VoipCarriers', {
resolveWithFullResponse: true,
simple: false,
auth: authAdmin,
json: true,
body: {
name: 'daveh',
account_sid: account_sid2,
application_sid
}
});
t.ok(result.statusCode === 400 && result.body.msg === 'application_sid does not exist for specified account_sid',
'fails to create voip_carrier with account_sid not matching application_sid');
result = await request.post('/VoipCarriers', {
resolveWithFullResponse: true,
simple: false,
auth: authAdmin,
json: true,
body: {
name: 'daveh',
account_sid: account_sid,
application_sid: 'xxx'
}
});
t.ok(result.statusCode === 400 && result.body.msg === 'unknown application_sid', 'fails to create voip_carrier with unknown application_sid');
result = await request.post('/VoipCarriers', {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
name: 'daveh',
account_sid,
application_sid
}
});
t.ok(result.statusCode === 201, 'successfully created customer PBX with account and application');
sid = result.body.sid;
await deleteObjectBySid(request, '/VoipCarriers', sid);
result = await request.post('/VoipCarriers', {
resolveWithFullResponse: true,
auth: authAdmin,
json: true,
body: {
name: 'daveh',
account_sid
}
});
t.ok(result.statusCode === 201, 'successfully created customer PBX with account only');
sid = result.body.sid;
await deleteObjectBySid(request, '/VoipCarriers', sid);
await deleteObjectBySid(request, '/Applications', application_sid);
await deleteObjectBySid(request, '/Accounts', account_sid);
await deleteObjectBySid(request, '/Accounts', account_sid2);
await deleteObjectBySid(request, '/ServiceProviders', service_provider_sid);
t.end();
}
catch (err) {