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

@ -7,10 +7,8 @@
*/
const common = require('../../common');
const settings = require('../../../container/loadSettings.js').loadSettings();
const supertest = require('supertest');
const api = supertest(`http://${settings.ip}:${settings.port}`);
let agent;
const apiKey = common.apiKey;
const apiVersion = 1;
@ -228,6 +226,8 @@ const testImports = {
};
describe(__filename, function () {
before(async function () { agent = await common.init(); });
Object.keys(testImports).forEach((testName) => {
describe(testName, function () {
const testPadId = makeid();
@ -239,7 +239,7 @@ describe(__filename, function () {
}
it('createPad', function (done) {
this.timeout(200);
api.get(`${endPoint('createPad')}&padID=${testPadId}`)
agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
})
@ -249,7 +249,8 @@ describe(__filename, function () {
it('setHTML', function (done) {
this.timeout(150);
api.get(`${endPoint('setHTML')}&padID=${testPadId}&html=${encodeURIComponent(test.input)}`)
agent.get(`${endPoint('setHTML')}&padID=${testPadId}` +
`&html=${encodeURIComponent(test.input)}`)
.expect((res) => {
if (res.body.code !== 0) throw new Error(`Error:${testName}`);
})
@ -259,7 +260,7 @@ describe(__filename, function () {
it('getHTML', function (done) {
this.timeout(150);
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect((res) => {
const gotHtml = res.body.data.html;
if (gotHtml !== test.wantHTML) {
@ -283,7 +284,7 @@ describe(__filename, function () {
it('getText', function (done) {
this.timeout(100);
api.get(`${endPoint('getText')}&padID=${testPadId}`)
agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect((res) => {
const gotText = res.body.data.text;
if (gotText !== test.wantText) {