add integration test

This commit is contained in:
Dave Horton
2021-05-07 08:33:13 -04:00
parent 081a83e121
commit fc61d3d2fa
8 changed files with 126 additions and 10 deletions
+1
View File
@@ -38,6 +38,7 @@ const {
} = require('@jambonz/db-helpers')({
host: process.env.JAMBONES_MYSQL_HOST,
user: process.env.JAMBONES_MYSQL_USER,
port: process.env.JAMBONES_MYSQL_PORT || 3306,
password: process.env.JAMBONES_MYSQL_PASSWORD,
database: process.env.JAMBONES_MYSQL_DATABASE,
connectionLimit: process.env.JAMBONES_MYSQL_CONNECTION_LIMIT || 10
+2
View File
@@ -186,6 +186,8 @@ service_provider_sid CHAR(36) NOT NULL COMMENT 'service provider that owns the c
registration_hook_sid CHAR(36) COMMENT 'webhook to call when devices underr this account attempt to register',
device_calling_application_sid CHAR(36) COMMENT 'application to use for outbound calling from an account',
is_active BOOLEAN NOT NULL DEFAULT true,
webhook_secret VARCHAR(36),
disable_cdrs BOOLEAN NOT NULL DEFAULT 0,
PRIMARY KEY (account_sid)
) COMMENT='An enterprise that uses the platform for comm services';
+20 -7
View File
@@ -529,7 +529,7 @@
</location>
<size>
<width>380.00</width>
<height>160.00</height>
<height>200.00</height>
</size>
<zorder>4</zorder>
<SQLField>
@@ -611,6 +611,19 @@
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[C7130A90-DBB4-424D-A9A9-CB203C32350C]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[webhook_secret]]></name>
<type><![CDATA[VARCHAR(36)]]></type>
<notNull><![CDATA[0]]></notNull>
<uid><![CDATA[CF25660D-AACA-4783-8A13-C7393D3B3D95]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[disable_cdrs]]></name>
<type><![CDATA[BOOLEAN]]></type>
<defaultValue><![CDATA[0]]></defaultValue>
<notNull><![CDATA[1]]></notNull>
<uid><![CDATA[341B2A8D-AE85-4FCA-8EA8-D6E6149511F4]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[11]]></labelWindowIndex>
<objectComment><![CDATA[An enterprise that uses the platform for comm services]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
@@ -1132,17 +1145,17 @@
<overviewPanelHidden><![CDATA[0]]></overviewPanelHidden>
<pageBoundariesVisible><![CDATA[0]]></pageBoundariesVisible>
<PageGridVisible><![CDATA[0]]></PageGridVisible>
<RightSidebarWidth><![CDATA[1515.000000]]></RightSidebarWidth>
<RightSidebarWidth><![CDATA[1213.000000]]></RightSidebarWidth>
<sidebarIndex><![CDATA[2]]></sidebarIndex>
<snapToGrid><![CDATA[0]]></snapToGrid>
<SourceSidebarWidth><![CDATA[0.000000]]></SourceSidebarWidth>
<SQLEditorFileFormatVersion><![CDATA[4]]></SQLEditorFileFormatVersion>
<uid><![CDATA[58C99A00-06C9-478C-A667-C63842E088F3]]></uid>
<windowHeight><![CDATA[1029.000000]]></windowHeight>
<windowLocationX><![CDATA[2912.000000]]></windowLocationX>
<windowLocationY><![CDATA[1869.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{424, 0}]]></windowScrollOrigin>
<windowWidth><![CDATA[2242.000000]]></windowWidth>
<windowHeight><![CDATA[977.000000]]></windowHeight>
<windowLocationX><![CDATA[2718.000000]]></windowLocationX>
<windowLocationY><![CDATA[1891.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{369.5, 4}]]></windowScrollOrigin>
<windowWidth><![CDATA[1490.000000]]></windowWidth>
</SQLDocumentInfo>
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>
<defaultLabelExpanded><![CDATA[1]]></defaultLabelExpanded>
+1
View File
@@ -2,6 +2,7 @@ const mysql = require('mysql2');
const pool = mysql.createPool({
host: process.env.JAMBONES_MYSQL_HOST,
user: process.env.JAMBONES_MYSQL_USER,
port: process.env.JAMBONES_MYSQL_PORT || 3306,
password: process.env.JAMBONES_MYSQL_PASSWORD,
database: process.env.JAMBONES_MYSQL_DATABASE,
connectionLimit: process.env.JAMBONES_MYSQL_CONNECTION_LIMIT || 10
+4 -1
View File
@@ -43,6 +43,7 @@ function validateUpdateCall(opts) {
const hasWhisper = opts.whisper;
const count = [
'call_hook',
'child_call_hook',
'call_status',
'listen_status',
'mute_status']
@@ -56,11 +57,13 @@ function validateUpdateCall(opts) {
case 1:
// good
break;
case 2:
if (opts.call_hook && opts.child_call_hook) break;
// eslint-disable-next-line no-fallthrough
default:
throw new DbErrorBadRequest('multiple options are not allowed in updateCall');
}
if (opts.call_hook && !opts.call_hook.url) throw new DbErrorBadRequest('missing call_hook.url');
if (opts.call_status && !['completed', 'no-answer'].includes(opts.call_status)) {
throw new DbErrorBadRequest('invalid call_status');
}
+2 -1
View File
@@ -1,11 +1,12 @@
{
"name": "jambonz-api-server",
"version": "1.2.0",
"version": "1.2.1",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "NODE_ENV=test JAMBONES_MYSQL_HOST=127.0.0.1 JAMBONES_MYSQL_USER=jambones_test JAMBONES_MYSQL_PASSWORD=jambones_test JAMBONES_MYSQL_DATABASE=jambones_test JAMBONES_REDIS_HOST=localhost JAMBONES_LOGLEVEL=error JAMBONES_CREATE_CALL_URL=http://localhost/v1/createCall node test/ | ./node_modules/.bin/tap-spec",
"integration-test": "NODE_ENV=test JAMBONES_TIME_SERIES_HOST=127.0.0.1 AWS_REGION='us-east-1' JAMBONES_CURRENCY=USD JWT_SECRET=foobarbazzle JAMBONES_MYSQL_HOST=127.0.0.1 JAMBONES_MYSQL_PORT=3360 JAMBONES_MYSQL_USER=jambones_test JAMBONES_MYSQL_PASSWORD=jambones_test JAMBONES_MYSQL_DATABASE=jambones_test JAMBONES_REDIS_HOST=localhost JAMBONES_REDIS_PORT=16379 JAMBONES_LOGLEVEL=debug JAMBONES_CREATE_CALL_URL=http://localhost/v1/createCall node test/serve-integration.js",
"coverage": "./node_modules/.bin/nyc --reporter html --report-dir ./coverage npm run test",
"jslint": "eslint app.js lib"
},
+13 -1
View File
@@ -4,10 +4,22 @@ services:
mysql:
image: mysql:5.7
ports:
- "3306:3306"
- "3360:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "127.0.0.1", "--protocol", "tcp"]
timeout: 5s
retries: 10
redis:
image: redis:5-alpine
ports:
- "16379:6379/tcp"
depends_on:
mysql:
condition: service_healthy
influxdb:
image: influxdb:1.8-alpine
ports:
- "8086:8086"
+83
View File
@@ -0,0 +1,83 @@
const exec = require('child_process').exec ;
let stopping = false;
process.on('SIGINT', async() => {
if (stopping) return;
stopping = true;
console.log('shutting down');
await stopDocker();
process.exit(0);
});
const startDocker = () => {
return new Promise((resolve, reject) => {
console.log('starting dockerized mysql and redis..')
exec(`docker-compose -f ${__dirname}/docker-compose-testbed.yaml up -d`, (err) => {
if (err) return reject(err);
setTimeout(() => {
console.log('mysql is running');
resolve();
}, 10000);
});
});
};
const createDb = () => {
return new Promise((resolve, reject) => {
console.log('creating database..')
exec(`mysql -h 127.0.0.1 -u root --protocol=tcp --port=3360 < ${__dirname}/../db/create_test_db.sql`, (err) => {
if (err) return reject(err);
resolve();
});
});
};
const createSchema = () => {
return new Promise((resolve, reject) => {
console.log('creating schema..')
exec(`mysql -h 127.0.0.1 -u root --protocol=tcp --port=3360 -D jambones_test < ${__dirname}/../db/jambones-sql.sql`, (err, stdout, stderr) => {
if (err) return reject(err);
resolve();
});
});
};
const seedDb = () => {
return new Promise((resolve, reject) => {
console.log('seeding database..')
exec(`mysql -h 127.0.0.1 -u root --protocol=tcp --port=3360 -D jambones_test < ${__dirname}/../db/create-default-service-provider-and-account.sql`, (err) => {
if (err) return reject(err);
exec(`mysql -h 127.0.0.1 -u root --protocol=tcp --port=3360 -D jambones_test < ${__dirname}/../db/create-admin-token.sql`, (err) => {
if (err) return reject(err);
exec(`node ${__dirname}/../db/reset_admin_password.js`, (err) => {
if (err) return reject(err);
resolve();
});
});
});
});
};
const stopDocker = () => {
return new Promise((resolve, reject) => {
console.log('stopping docker network..')
exec(`docker-compose -f ${__dirname}/docker-compose-testbed.yaml down`, (err) => {
if (err) return reject(err);
resolve();
});
})
};
startDocker()
.then(createDb)
.then(createSchema)
.then(seedDb)
.then(() => {
console.log('ready for testing!');
require('..');
})
.catch(async(err) => {
console.error({err}, 'Error running integration test');
await stopDocker();
process.exit(-1);
});