mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 09:26:14 -04:00
tests: Use the supertest agent from common.js
for backend tests
This commit is contained in:
parent
5a91cf1b49
commit
7dae5e3db8
10 changed files with 139 additions and 189 deletions
|
@ -8,10 +8,8 @@
|
|||
|
||||
const common = require('../../common');
|
||||
const fs = require('fs');
|
||||
const settings = require('../../../../node/utils/Settings');
|
||||
const supertest = require('supertest');
|
||||
|
||||
const api = supertest(`http://${settings.ip}:${settings.port}`);
|
||||
let agent;
|
||||
const apiKey = common.apiKey;
|
||||
let apiVersion = 1;
|
||||
const testPadId = makeid();
|
||||
|
@ -19,10 +17,12 @@ const testPadId = makeid();
|
|||
const endPoint = (point, version) => `/api/${version || apiVersion}/${point}?apikey=${apiKey}`;
|
||||
|
||||
describe(__filename, function () {
|
||||
before(async function () { agent = await common.init(); });
|
||||
|
||||
describe('Connectivity For Character Encoding', function () {
|
||||
it('can connect', function (done) {
|
||||
this.timeout(250);
|
||||
api.get('/api/')
|
||||
agent.get('/api/')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done);
|
||||
});
|
||||
|
@ -31,7 +31,7 @@ describe(__filename, function () {
|
|||
describe('API Versioning', function () {
|
||||
this.timeout(150);
|
||||
it('finds the version tag', function (done) {
|
||||
api.get('/api/')
|
||||
agent.get('/api/')
|
||||
.expect((res) => {
|
||||
apiVersion = res.body.currentVersion;
|
||||
if (!res.body.currentVersion) throw new Error('No version set in API');
|
||||
|
@ -47,7 +47,7 @@ describe(__filename, function () {
|
|||
// This is broken because Etherpad doesn't handle HTTP codes properly see #2343
|
||||
// If your APIKey is password you deserve to fail all tests anyway
|
||||
const permErrorURL = `/api/${apiVersion}/createPad?apikey=password&padID=test`;
|
||||
api.get(permErrorURL)
|
||||
agent.get(permErrorURL)
|
||||
.expect(401, done);
|
||||
});
|
||||
});
|
||||
|
@ -55,7 +55,7 @@ describe(__filename, function () {
|
|||
describe('createPad', function () {
|
||||
it('creates a new Pad', function (done) {
|
||||
this.timeout(150);
|
||||
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');
|
||||
})
|
||||
|
@ -68,7 +68,7 @@ describe(__filename, function () {
|
|||
it('Sets the HTML of a Pad attempting to weird utf8 encoded content', function (done) {
|
||||
this.timeout(1000);
|
||||
fs.readFile('tests/backend/specs/api/emojis.html', 'utf8', (err, html) => {
|
||||
api.post(endPoint('setHTML'))
|
||||
agent.post(endPoint('setHTML'))
|
||||
.send({
|
||||
padID: testPadId,
|
||||
html,
|
||||
|
@ -85,7 +85,7 @@ describe(__filename, function () {
|
|||
describe('getHTML', function () {
|
||||
it('get the HTML of Pad with emojis', function (done) {
|
||||
this.timeout(400);
|
||||
api.get(`${endPoint('getHTML')}&padID=${testPadId}`)
|
||||
agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
|
||||
.expect((res) => {
|
||||
if (res.body.data.html.indexOf('🇼') === -1) {
|
||||
throw new Error('Unable to get the HTML');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue