tests: Use the supertest agent from common.js for backend tests

This commit is contained in:
Richard Hansen 2021-02-16 18:35:50 -05:00
parent 5a91cf1b49
commit 7dae5e3db8
10 changed files with 139 additions and 189 deletions

View file

@ -6,21 +6,20 @@
* Section "GLOBAL FUNCTIONS" in src/node/db/API.js
*/
const common = require('../../common');
const settings = require('../../../../node/utils/Settings');
const supertest = require('supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
let agent;
const apiKey = common.apiKey;
const apiVersion = '1.2.14';
const endPoint = (point, version) => `/api/${version || apiVersion}/${point}?apikey=${apiKey}`;
describe(__filename, function () {
before(async function () { agent = await common.init(); });
describe('Connectivity for instance-level API tests', function () {
it('can connect', function (done) {
this.timeout(150);
api.get('/api/')
agent.get('/api/')
.expect('Content-Type', /json/)
.expect(200, done);
});
@ -29,7 +28,7 @@ describe(__filename, function () {
describe('getStats', function () {
it('Gets the stats of a running instance', function (done) {
this.timeout(100);
api.get(endPoint('getStats'))
agent.get(endPoint('getStats'))
.expect((res) => {
if (res.body.code !== 0) throw new Error('getStats() failed');