etherpad-lite/src/tests/backend/specs/api/instance.js

55 lines
1.9 KiB
JavaScript
Raw Normal View History

'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
*/
const common = require('../../common');
2020-04-04 19:11:46 +02:00
let agent;
const apiKey = common.apiKey;
const apiVersion = '1.2.14';
2020-04-04 19:11:46 +02:00
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) {
agent.get('/api/')
.expect('Content-Type', /json/)
.expect(200, done);
});
2020-04-04 19:11:46 +02:00
});
describe('getStats', function () {
it('Gets the stats of a running instance', function (done) {
agent.get(endPoint('getStats'))
.expect((res) => {
if (res.body.code !== 0) throw new Error('getStats() failed');
2020-04-04 19:11:46 +02: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-04-04 19:11:46 +02: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-04-04 19:11:46 +02: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)}`);
}
})
.expect('Content-Type', /json/)
.expect(200, done);
});
2020-04-04 19:11:46 +02:00
});
});