revamp db - refactor webhooks

This commit is contained in:
Dave Horton
2020-01-28 10:30:07 -05:00
parent 10074504c5
commit 87208bc669
13 changed files with 675 additions and 252 deletions
+40 -3
View File
@@ -28,7 +28,20 @@ test('account tests', async(t) => {
json: true,
body: {
name: 'daveh',
service_provider_sid
service_provider_sid,
registration_hook: {
url: 'http://example.com/reg',
method: 'get'
},
device_calling_hook: {
url: 'http://example.com/device',
method: 'get',
username: 'foo',
password: 'abr'
},
error_hook: {
url: 'http://example.com/error'
}
}
});
t.ok(result.statusCode === 201, 'successfully created account');
@@ -39,7 +52,13 @@ test('account tests', async(t) => {
auth: authAdmin,
json: true,
});
t.ok(result.length === 1 , 'successfully queried all accounts');
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');
/* query one accounts */
result = await request.get(`/Accounts/${sid}`, {
@@ -47,6 +66,7 @@ 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}`, {
@@ -54,11 +74,28 @@ test('account tests', async(t) => {
json: true,
resolveWithFullResponse: true,
body: {
name: 'robb'
name: 'robb',
registration_hook: {
url: 'http://example.com/reg2',
method: 'get'
},
error_hook: {
webhook_sid: error_hook_sid,
method: 'post'
}
}
});
t.ok(result.statusCode === 204, 'successfully updated account');
result = await request.get(`/Accounts/${sid}`, {
auth: authAdmin,
json: true,
});
//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');
/* assign phone number to account */
result = await request.put(`/PhoneNumbers/${phone_number_sid}`, {
auth: authAdmin,
+10 -3
View File
@@ -32,8 +32,13 @@ test('application tests', async(t) => {
body: {
name: 'daveh',
account_sid,
call_hook: 'http://example.com',
call_status_hook: 'http://example.com'
call_hook: {
url: 'http://example.com'
},
call_status_hook: {
url: 'http://example.com/status',
method: 'POST'
}
}
});
t.ok(result.statusCode === 201, 'successfully created application');
@@ -60,7 +65,9 @@ test('application tests', async(t) => {
json: true,
resolveWithFullResponse: true,
body: {
call_hook: 'http://example2.com'
call_hook: {
url: 'http://example2.com'
}
}
});
t.ok(result.statusCode === 204, 'successfully updated application');
+20 -9
View File
@@ -55,7 +55,10 @@ test('authentication tests', async(t) => {
simple: false,
json: true,
body: {
name: 'accountA1'
name: 'accountA1',
registration_hook: {
url: 'http://example.com'
}
}
});
t.ok(result.statusCode === 201, 'successfully created account A1 using service provider token A');
@@ -216,8 +219,12 @@ test('authentication tests', async(t) => {
json: true,
body: {
name: 'A1-app',
call_hook: 'http://example.com',
call_status_hook: 'http://example.com'
call_hook: {
url: 'http://example.com'
},
call_status_hook: {
url: 'http://example.com'
}
}
});
t.ok(result.statusCode === 201, 'successfully created application for account A1 (using account level token)');
@@ -231,8 +238,12 @@ test('authentication tests', async(t) => {
body: {
name: 'A2-app',
account_sid: accA2,
call_hook: 'http://example.com',
call_status_hook: 'http://example.com'
call_hook: {
url: 'http://example.com',
},
call_status_hook: {
url: 'http://example.com'
}
}
});
t.ok(result.statusCode === 400 && result.body.msg === 'insufficient privileges to create an application under the specified account',
@@ -246,8 +257,8 @@ test('authentication tests', async(t) => {
body: {
name: 'A2-app',
account_sid: accA2,
call_hook: 'http://example.com',
call_status_hook: 'http://example.com'
call_hook: {url: 'http://example.com'},
call_status_hook: {url: 'http://example.com'}
}
});
t.ok(result.statusCode === 201, 'successfully created application for account A2 (using service provider token A)');
@@ -261,8 +272,8 @@ test('authentication tests', async(t) => {
body: {
name: 'B1-app',
account_sid: accB1,
call_hook: 'http://example.com',
call_status_hook: 'http://example.com'
call_hook: {url: 'http://example.com'},
call_status_hook: {url: 'http://example.com'}
}
});
t.ok(result.statusCode === 201, 'successfully created application for account B1 (using service provider token B)');