mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 08:26:16 -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
|
@ -2,11 +2,8 @@
|
|||
|
||||
const assert = require('assert').strict;
|
||||
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;
|
||||
let apiVersion = 1;
|
||||
let groupID = '';
|
||||
|
@ -17,10 +14,12 @@ let padID = makeid();
|
|||
const endPoint = (point) => `/api/${apiVersion}/${point}?apikey=${apiKey}`;
|
||||
|
||||
describe(__filename, function () {
|
||||
before(async function () { agent = await common.init(); });
|
||||
|
||||
describe('API Versioning', function () {
|
||||
it('errors if can not connect', async function () {
|
||||
this.timeout(200);
|
||||
await api.get('/api/')
|
||||
await agent.get('/api/')
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
assert(res.body.currentVersion);
|
||||
|
@ -62,7 +61,7 @@ describe(__filename, function () {
|
|||
describe('API: Group creation and deletion', function () {
|
||||
it('createGroup', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(endPoint('createGroup'))
|
||||
await agent.get(endPoint('createGroup'))
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -74,7 +73,7 @@ describe(__filename, function () {
|
|||
|
||||
it('listSessionsOfGroup for empty group', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('listSessionsOfGroup')}&groupID=${groupID}`)
|
||||
await agent.get(`${endPoint('listSessionsOfGroup')}&groupID=${groupID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -85,7 +84,7 @@ describe(__filename, function () {
|
|||
|
||||
it('deleteGroup', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('deleteGroup')}&groupID=${groupID}`)
|
||||
await agent.get(`${endPoint('deleteGroup')}&groupID=${groupID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -95,7 +94,7 @@ describe(__filename, function () {
|
|||
|
||||
it('createGroupIfNotExistsFor', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createGroupIfNotExistsFor')}&groupMapper=management`)
|
||||
await agent.get(`${endPoint('createGroupIfNotExistsFor')}&groupMapper=management`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -108,7 +107,7 @@ describe(__filename, function () {
|
|||
// Creates a group, creates 2 sessions, 2 pads and then deletes the group.
|
||||
it('createGroup', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(endPoint('createGroup'))
|
||||
await agent.get(endPoint('createGroup'))
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -120,7 +119,7 @@ describe(__filename, function () {
|
|||
|
||||
it('createAuthor', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(endPoint('createAuthor'))
|
||||
await agent.get(endPoint('createAuthor'))
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -132,8 +131,8 @@ describe(__filename, function () {
|
|||
|
||||
it('createSession', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createSession')
|
||||
}&authorID=${authorID}&groupID=${groupID}&validUntil=999999999999`)
|
||||
await agent.get(`${endPoint('createSession')}&authorID=${authorID}&groupID=${groupID}` +
|
||||
'&validUntil=999999999999')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -145,8 +144,8 @@ describe(__filename, function () {
|
|||
|
||||
it('createSession', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createSession')
|
||||
}&authorID=${authorID}&groupID=${groupID}&validUntil=999999999999`)
|
||||
await agent.get(`${endPoint('createSession')}&authorID=${authorID}&groupID=${groupID}` +
|
||||
'&validUntil=999999999999')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -158,7 +157,7 @@ describe(__filename, function () {
|
|||
|
||||
it('createGroupPad', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=x1234567`)
|
||||
await agent.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=x1234567`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -168,7 +167,7 @@ describe(__filename, function () {
|
|||
|
||||
it('createGroupPad', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=x12345678`)
|
||||
await agent.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=x12345678`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -178,7 +177,7 @@ describe(__filename, function () {
|
|||
|
||||
it('deleteGroup', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('deleteGroup')}&groupID=${groupID}`)
|
||||
await agent.get(`${endPoint('deleteGroup')}&groupID=${groupID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -191,7 +190,7 @@ describe(__filename, function () {
|
|||
describe('API: Author creation', function () {
|
||||
it('createGroup', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(endPoint('createGroup'))
|
||||
await agent.get(endPoint('createGroup'))
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -203,7 +202,7 @@ describe(__filename, function () {
|
|||
|
||||
it('createAuthor', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(endPoint('createAuthor'))
|
||||
await agent.get(endPoint('createAuthor'))
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -214,7 +213,7 @@ describe(__filename, function () {
|
|||
|
||||
it('createAuthor with name', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createAuthor')}&name=john`)
|
||||
await agent.get(`${endPoint('createAuthor')}&name=john`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -226,7 +225,7 @@ describe(__filename, function () {
|
|||
|
||||
it('createAuthorIfNotExistsFor', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createAuthorIfNotExistsFor')}&authorMapper=chris`)
|
||||
await agent.get(`${endPoint('createAuthorIfNotExistsFor')}&authorMapper=chris`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -237,7 +236,7 @@ describe(__filename, function () {
|
|||
|
||||
it('getAuthorName', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('getAuthorName')}&authorID=${authorID}`)
|
||||
await agent.get(`${endPoint('getAuthorName')}&authorID=${authorID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -250,8 +249,8 @@ describe(__filename, function () {
|
|||
describe('API: Sessions', function () {
|
||||
it('createSession', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createSession')
|
||||
}&authorID=${authorID}&groupID=${groupID}&validUntil=999999999999`)
|
||||
await agent.get(`${endPoint('createSession')}&authorID=${authorID}&groupID=${groupID}` +
|
||||
'&validUntil=999999999999')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -263,7 +262,7 @@ describe(__filename, function () {
|
|||
|
||||
it('getSessionInfo', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('getSessionInfo')}&sessionID=${sessionID}`)
|
||||
await agent.get(`${endPoint('getSessionInfo')}&sessionID=${sessionID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -276,7 +275,7 @@ describe(__filename, function () {
|
|||
|
||||
it('listSessionsOfGroup', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('listSessionsOfGroup')}&groupID=${groupID}`)
|
||||
await agent.get(`${endPoint('listSessionsOfGroup')}&groupID=${groupID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -287,7 +286,7 @@ describe(__filename, function () {
|
|||
|
||||
it('deleteSession', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('deleteSession')}&sessionID=${sessionID}`)
|
||||
await agent.get(`${endPoint('deleteSession')}&sessionID=${sessionID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -297,7 +296,7 @@ describe(__filename, function () {
|
|||
|
||||
it('getSessionInfo of deleted session', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('getSessionInfo')}&sessionID=${sessionID}`)
|
||||
await agent.get(`${endPoint('getSessionInfo')}&sessionID=${sessionID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -309,7 +308,7 @@ describe(__filename, function () {
|
|||
describe('API: Group pad management', function () {
|
||||
it('listPads', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('listPads')}&groupID=${groupID}`)
|
||||
await agent.get(`${endPoint('listPads')}&groupID=${groupID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -320,7 +319,7 @@ describe(__filename, function () {
|
|||
|
||||
it('createGroupPad', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=${padID}`)
|
||||
await agent.get(`${endPoint('createGroupPad')}&groupID=${groupID}&padName=${padID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -331,7 +330,7 @@ describe(__filename, function () {
|
|||
|
||||
it('listPads after creating a group pad', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('listPads')}&groupID=${groupID}`)
|
||||
await agent.get(`${endPoint('listPads')}&groupID=${groupID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -344,7 +343,7 @@ describe(__filename, function () {
|
|||
describe('API: Pad security', function () {
|
||||
it('getPublicStatus', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('getPublicStatus')}&padID=${padID}`)
|
||||
await agent.get(`${endPoint('getPublicStatus')}&padID=${padID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -355,7 +354,7 @@ describe(__filename, function () {
|
|||
|
||||
it('setPublicStatus', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('setPublicStatus')}&padID=${padID}&publicStatus=true`)
|
||||
await agent.get(`${endPoint('setPublicStatus')}&padID=${padID}&publicStatus=true`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -365,7 +364,7 @@ describe(__filename, function () {
|
|||
|
||||
it('getPublicStatus after changing public status', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('getPublicStatus')}&padID=${padID}`)
|
||||
await agent.get(`${endPoint('getPublicStatus')}&padID=${padID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
@ -382,7 +381,7 @@ describe(__filename, function () {
|
|||
describe('API: Misc', function () {
|
||||
it('listPadsOfAuthor', async function () {
|
||||
this.timeout(100);
|
||||
await api.get(`${endPoint('listPadsOfAuthor')}&authorID=${authorID}`)
|
||||
await agent.get(`${endPoint('listPadsOfAuthor')}&authorID=${authorID}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue