Simplify test (#145)

* feat: add create-call timeout test

* feat: single webhook-test-scaffold and basic auth callhook testcase

* cleanup

Co-authored-by: Quan Luu <quan.luuhoang8@gmail.com>
Co-authored-by: xquanluu <110280845+xquanluu@users.noreply.github.com>
This commit is contained in:
Dave Horton
2022-08-10 14:13:25 +02:00
committed by GitHub
parent 3298918322
commit 2a4f8e3ff9
13 changed files with 245 additions and 120 deletions

View File

@@ -1,10 +1,9 @@
const test = require('tape');
const { sippUac } = require('./sipp')('test_fs');
const bent = require('bent');
const getJSON = bent('json')
const clearModule = require('clear-module');
const HttpRequestor = require('../lib/utils/http-requestor');
const provisionCallHook = require('./utils')
const getJSON = bent('json')
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
@@ -24,8 +23,9 @@ test('test create-call timeout', async(t) => {
try {
await connect(srf);
let account_sid = '622f62e4-303a-49f2-bbe0-eb1e1714e37a'
const post = bent('http://127.0.0.1:3000/', 'POST', 'json', 201)
// GIVEN
let account_sid = '622f62e4-303a-49f2-bbe0-eb1e1714e37a';
const post = bent('http://127.0.0.1:3000/', 'POST', 'json', 201);
post('v1/createCall', {
'account_sid':account_sid,
'timeout': 1,
@@ -37,7 +37,8 @@ test('test create-call timeout', async(t) => {
"to": {
"type": "phone",
"number": "15583084809"
}})
}});
//THEN
await sippUac('uas-timeout-cancel.xml', '172.38.0.10');
disconnect();
} catch (err) {
@@ -47,6 +48,48 @@ test('test create-call timeout', async(t) => {
}
});
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
test('test create-call call-hook basic authentication', async(t) => {
clearModule.all();
const {srf, disconnect} = require('../app');
try {
await connect(srf);
// GIVEN
let from = 'call_hook_basic_authentication';
let account_sid = '622f62e4-303a-49f2-bbe0-eb1e1714e37a';
const post = bent('http://127.0.0.1:3000/', 'POST', 'json', 201);
post('v1/createCall', {
'account_sid':account_sid,
"call_hook": {
"url": "http://127.0.0.1:3100/",
"method": "POST",
"username": "username",
"password": "password"
},
"from": from,
"to": {
"type": "phone",
"number": "15583084809"
}});
let verbs = [
{
"verb": "say",
"text": "hello"
}
];
provisionCallHook(from, verbs);
//THEN
await sippUac('uas.xml', '172.38.0.10', from);
let obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}`)
t.ok(obj.headers.Authorization = 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=',
'create-call: call-hook contains basic authentication header');
disconnect();
} catch (err) {
console.log(`error received: ${err}`);
disconnect();
t.error(err);
}
});