Skip to content

Commit 8515ae7

Browse files
committed
Fixed condition.
1 parent 33dd6c8 commit 8515ae7

File tree

1 file changed

+86
-76
lines changed

1 file changed

+86
-76
lines changed

static/tests/backend/specs/exportHTML.js

Lines changed: 86 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,34 @@
22

33
const common = require('ep_etherpad-lite/tests/backend/common');
44
const randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
5+
import {generateJWTToken, generateJWTTokenUser} from "ep_etherpad-lite/tests/backend/common";
56

67
let agent;
7-
const apiKey = common.apiKey;
88
const apiVersion = 1;
99

1010
const buildHTML = (body) => `<html><body>${body}</body></html>`;
1111
const getHTMLEndPointFor =
12-
(padID, callback) => `/api/${apiVersion}/getHTML?apikey=${apiKey}&padID=${padID}`;
12+
(padID, callback) => `/api/${apiVersion}/getHTML?padID=${padID}`;
1313

1414
// Creates a pad and returns the pad id. Calls the callback when finished.
15-
const createPad = (padID, callback) => {
16-
agent.get(`/api/${apiVersion}/createPad?apikey=${apiKey}&padID=${padID}`)
17-
.end((err, res) => {
18-
if (err || (res.body.code !== 0)) callback(new Error('Unable to create new Pad'));
19-
20-
callback(padID);
21-
});
15+
const createPad = async (padID, callback) => {
16+
agent.get(`/api/${apiVersion}/createPad?padID=${padID}`)
17+
.set("Authorization", await generateJWTToken())
18+
.end((err, res) => {
19+
if (err || (res.body.code !== 0)) callback(new Error('Unable to create new Pad'));
20+
21+
callback(padID);
22+
});
2223
};
2324

24-
const setHTML = (padID, html, callback) => {
25-
agent.get(`/api/${apiVersion}/setHTML?apikey=${apiKey}&padID=${padID}&html=${html}`)
26-
.end((err, res) => {
27-
if (err || (res.body.code !== 0)) callback(new Error('Unable to set pad HTML'));
25+
const setHTML = async (padID, html, callback) => {
26+
agent.get(`/api/${apiVersion}/setHTML?padID=${padID}&html=${html}`)
27+
.set("Authorization", await generateJWTToken())
28+
.end((err, res) => {
29+
if (err || (res.body.code !== 0)) callback(new Error('Unable to set pad HTML'));
2830

29-
callback(null, padID);
30-
});
31+
callback(null, padID);
32+
});
3133
};
3234

3335
describe('export Subscript to HTML', function () {
@@ -37,34 +39,36 @@ describe('export Subscript to HTML', function () {
3739
before(async function () { agent = await common.init(); });
3840

3941
// create a new pad before each test run
40-
beforeEach(function (done) {
41-
padID = randomString(5);
42+
beforeEach(async function (done) {
43+
padID = randomString(5);
4244

43-
createPad(padID, () => {
44-
setHTML(padID, html(), done);
45-
});
45+
await createPad(padID, async () => {
46+
await setHTML(padID, html(), done);
47+
});
4648
});
4749

4850
context('when pad text has one Subscript', function () {
4951
before(async function () {
5052
html = () => buildHTML('<sub>Hello world</sub>');
5153
});
5254

53-
it('returns ok', function (done) {
54-
agent.get(getHTMLEndPointFor(padID))
55-
.expect('Content-Type', /json/)
56-
.expect(200, done);
55+
it('returns ok', async function (done) {
56+
agent.get(getHTMLEndPointFor(padID))
57+
.set("Authorization", await generateJWTToken())
58+
.expect('Content-Type', /json/)
59+
.expect(200, done);
5760
});
5861

59-
it('returns HTML with Subscript HTML tags', function (done) {
60-
agent.get(getHTMLEndPointFor(padID))
61-
.expect((res) => {
62-
const html = res.body.data.html;
63-
if (html.indexOf('<sub>Hello world</sub>') === -1) {
64-
throw new Error('No sub tag detected');
65-
}
66-
})
67-
.end(done);
62+
it('returns HTML with Subscript HTML tags', async function (done) {
63+
agent.get(getHTMLEndPointFor(padID))
64+
.set("Authorization", await generateJWTToken())
65+
.expect((res) => {
66+
const html = res.body.data.html;
67+
if (html.indexOf('<sub>Hello world</sub>') === -1) {
68+
throw new Error('No sub tag detected');
69+
}
70+
})
71+
.end(done);
6872
});
6973
});
7074

@@ -74,22 +78,24 @@ describe('export Subscript to HTML', function () {
7478
});
7579

7680

77-
it('returns ok', function (done) {
78-
agent.get(getHTMLEndPointFor(padID))
79-
.expect('Content-Type', /json/)
80-
.expect(200, done);
81+
it('returns ok', async function (done) {
82+
agent.get(getHTMLEndPointFor(padID))
83+
.set("Authorization", await generateJWTToken())
84+
.expect('Content-Type', /json/)
85+
.expect(200, done);
8186
});
8287

83-
it('returns HTML with Multiple Subscripts HTML tags', function (done) {
84-
agent.get(getHTMLEndPointFor(padID))
85-
.expect((res) => {
86-
const html = res.body.data.html;
87-
if (html.indexOf('<sub>Hello world</sub>') === -1) {
88-
throw new Error('No sub tag detected');
89-
}
90-
if (html.indexOf('<sub>Foo</sub>') === -1) throw new Error('No sub tag detected');
91-
})
92-
.end(done);
88+
it('returns HTML with Multiple Subscripts HTML tags', async function (done) {
89+
agent.get(getHTMLEndPointFor(padID))
90+
.set("Authorization", await generateJWTToken())
91+
.expect((res) => {
92+
const html = res.body.data.html;
93+
if (html.indexOf('<sub>Hello world</sub>') === -1) {
94+
throw new Error('No sub tag detected');
95+
}
96+
if (html.indexOf('<sub>Foo</sub>') === -1) throw new Error('No sub tag detected');
97+
})
98+
.end(done);
9399
});
94100
});
95101
});
@@ -113,21 +119,23 @@ describe('export Superscript to HTML', function () {
113119
});
114120

115121

116-
it('returns ok', function (done) {
117-
agent.get(getHTMLEndPointFor(padID))
118-
.expect('Content-Type', /json/)
119-
.expect(200, done);
122+
it('returns ok', async function (done) {
123+
agent.get(getHTMLEndPointFor(padID))
124+
.set("Authorization", await generateJWTToken())
125+
.expect('Content-Type', /json/)
126+
.expect(200, done);
120127
});
121128

122-
it('returns HTML with Suberscript HTML tags', function (done) {
123-
agent.get(getHTMLEndPointFor(padID))
124-
.expect((res) => {
125-
const html = res.body.data.html;
126-
if (html.indexOf('<sup>Hello world</sup>') === -1) {
127-
throw new Error('No sup tag detected');
128-
}
129-
})
130-
.end(done);
129+
it('returns HTML with Suberscript HTML tags', async function (done) {
130+
agent.get(getHTMLEndPointFor(padID))
131+
.set("Authorization", await generateJWTToken())
132+
.expect((res) => {
133+
const html = res.body.data.html;
134+
if (html.indexOf('<sup>Hello world</sup>') === -1) {
135+
throw new Error('No sup tag detected');
136+
}
137+
})
138+
.end(done);
131139
});
132140
});
133141

@@ -136,24 +144,26 @@ describe('export Superscript to HTML', function () {
136144
html = () => buildHTML('<sup>Hello world</sup><br/><sup>Foo</sup>');
137145
});
138146

139-
it('returns ok', function (done) {
140-
agent.get(getHTMLEndPointFor(padID))
141-
.expect('Content-Type', /json/)
142-
.expect(200, done);
147+
it('returns ok', async function (done) {
148+
agent.get(getHTMLEndPointFor(padID))
149+
.set("Authorization", await generateJWTToken())
150+
.expect('Content-Type', /json/)
151+
.expect(200, done);
143152
});
144153

145-
it('returns HTML with Multiple Superscripts HTML tags', function (done) {
146-
agent.get(getHTMLEndPointFor(padID))
147-
.expect((res) => {
148-
const html = res.body.data.html;
149-
if (html.indexOf('<sup>Hello world</sup>') === -1) {
150-
throw new Error('No sup tag detected');
151-
}
152-
if (html.indexOf('<sup>Foo</sup>') === -1) {
153-
throw new Error('No sup tag detected');
154-
}
155-
})
156-
.end(done);
154+
it('returns HTML with Multiple Superscripts HTML tags', async function (done) {
155+
agent.get(getHTMLEndPointFor(padID))
156+
.set("Authorization", await generateJWTToken())
157+
.expect((res) => {
158+
const html = res.body.data.html;
159+
if (html.indexOf('<sup>Hello world</sup>') === -1) {
160+
throw new Error('No sup tag detected');
161+
}
162+
if (html.indexOf('<sup>Foo</sup>') === -1) {
163+
throw new Error('No sup tag detected');
164+
}
165+
})
166+
.end(done);
157167
});
158168
});
159169
});

0 commit comments

Comments
 (0)