2021-02-16 18:25:15 -05:00
|
|
|
'use strict';
|
|
|
|
|
2020-04-04 19:11:46 +02:00
|
|
|
/*
|
|
|
|
* Tests for the instance-level APIs
|
|
|
|
*
|
|
|
|
* Section "GLOBAL FUNCTIONS" in src/node/db/API.js
|
|
|
|
*/
|
2020-10-08 01:37:17 -04:00
|
|
|
const common = require('../../common');
|
2020-04-04 19:11:46 +02:00
|
|
|
|
2021-02-16 18:35:50 -05:00
|
|
|
let agent;
|
2020-10-08 01:37:17 -04:00
|
|
|
const apiKey = common.apiKey;
|
2020-11-23 13:21:51 -05:00
|
|
|
const apiVersion = '1.2.14';
|
2020-04-04 19:11:46 +02:00
|
|
|
|
2021-02-16 18:25:15 -05:00
|
|
|
const endPoint = (point, version) => `/api/${version || apiVersion}/${point}?apikey=${apiKey}`;
|
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe(__filename, function () {
|
2021-02-16 18:35:50 -05:00
|
|
|
before(async function () { agent = await common.init(); });
|
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe('Connectivity for instance-level API tests', function () {
|
|
|
|
it('can connect', function (done) {
|
2021-02-16 18:35:50 -05:00
|
|
|
agent.get('/api/')
|
2020-10-09 18:19:46 -04:00
|
|
|
.expect('Content-Type', /json/)
|
2020-11-23 13:21:51 -05:00
|
|
|
.expect(200, done);
|
2020-10-09 18:19:46 -04:00
|
|
|
});
|
2020-04-04 19:11:46 +02:00
|
|
|
});
|
|
|
|
|
2020-11-23 13:21:51 -05:00
|
|
|
describe('getStats', function () {
|
|
|
|
it('Gets the stats of a running instance', function (done) {
|
2021-02-16 18:35:50 -05:00
|
|
|
agent.get(endPoint('getStats'))
|
2020-11-23 13:21:51 -05:00
|
|
|
.expect((res) => {
|
|
|
|
if (res.body.code !== 0) throw new Error('getStats() failed');
|
2020-04-04 19:11:46 +02:00
|
|
|
|
2021-02-16 18:25:15 -05:00
|
|
|
if (!('totalPads' in res.body.data && typeof res.body.data.totalPads === 'number')) {
|
|
|
|
throw new Error('Response to getStats() does not contain field totalPads, or ' +
|
|
|
|
`it's not a number: ${JSON.stringify(res.body.data)}`);
|
2020-10-09 18:19:46 -04:00
|
|
|
}
|
2020-04-04 19:11:46 +02:00
|
|
|
|
2021-02-16 18:25:15 -05:00
|
|
|
if (!('totalSessions' in res.body.data &&
|
|
|
|
typeof res.body.data.totalSessions === 'number')) {
|
|
|
|
throw new Error('Response to getStats() does not contain field totalSessions, or ' +
|
|
|
|
`it's not a number: ${JSON.stringify(res.body.data)}`);
|
2020-10-09 18:19:46 -04:00
|
|
|
}
|
2020-04-04 19:11:46 +02:00
|
|
|
|
2021-02-16 18:25:15 -05:00
|
|
|
if (!('totalActivePads' in res.body.data &&
|
|
|
|
typeof res.body.data.totalActivePads === 'number')) {
|
|
|
|
throw new Error('Response to getStats() does not contain field totalActivePads, or ' +
|
|
|
|
`it's not a number: ${JSON.stringify(res.body.data)}`);
|
2020-10-09 18:19:46 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200, done);
|
|
|
|
});
|
2020-04-04 19:11:46 +02:00
|
|
|
});
|
|
|
|
});
|