ep_comments_page 10.0.2 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/apiUtils.js +38 -21
- package/exportHTML.js +1 -1
- package/index.js +30 -62
- package/locales/es.json +10 -1
- package/locales/fr.json +8 -7
- package/locales/ga.json +31 -0
- package/locales/got.json +15 -0
- package/locales/gur.json +0 -1
- package/locales/ha.json +0 -1
- package/locales/hu.json +4 -2
- package/locales/kaa.json +31 -0
- package/locales/kab.json +14 -0
- package/locales/ko.json +3 -2
- package/locales/lb.json +3 -2
- package/locales/nl.json +2 -2
- package/locales/pa.json +15 -0
- package/locales/pl.json +11 -9
- package/locales/pms.json +31 -0
- package/locales/ps.json +29 -0
- package/locales/ro.json +15 -0
- package/locales/sq.json +2 -1
- package/package.json +14 -18
- package/static/js/index.js +6 -1
- package/static/tests/backend/specs/api/commentReplies.js +56 -54
- package/static/tests/backend/specs/api/comments.js +57 -55
- package/static/tests/backend/specs/api/exportEtherpad.js +12 -4
- package/static/tests/backend/specs/api/exportHTML.js +35 -25
- package/static/tests/backend/specs/padCopy.js +18 -15
- package/static/tests/backend/specs/padRemove.js +18 -15
- package/static/tests/backend/specs/readOnlyPad.js +6 -4
- package/static/tests/utils.js +11 -9
- /package/static/tests/backend/{specs/api → fixtures}/test.etherpad +0 -0
package/locales/ro.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@metadata": {
|
|
3
|
+
"authors": [
|
|
4
|
+
"SZ475"
|
|
5
|
+
]
|
|
6
|
+
},
|
|
7
|
+
"ep_comments_page.comment": "Comentează",
|
|
8
|
+
"ep_comments_page.comments": "Comentarii",
|
|
9
|
+
"ep_comments_page.comments_template.from": "De la",
|
|
10
|
+
"ep_comments_page.comments_template.accept_change.value": "Acceptă schimbarea",
|
|
11
|
+
"ep_comments_page.comments_template.revert_change.value": "Anulează schimbarea",
|
|
12
|
+
"ep_comments_page.comments_template.to": "Către",
|
|
13
|
+
"ep_comments_page.error.edit_unauth": "Nu poți edita comentariile altor utilizatori!",
|
|
14
|
+
"ep_comments_page.error.delete_unauth": "Nu poți șterge comentariile altor utilizatori!"
|
|
15
|
+
}
|
package/locales/sq.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"description": "Adds comments on sidebar and link it to the text. For no-skin use ep_page_view.",
|
|
3
3
|
"name": "ep_comments_page",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "11.0.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Nicolas Lescop",
|
|
7
7
|
"email": "limplementeur@gmail.com"
|
|
@@ -22,34 +22,30 @@
|
|
|
22
22
|
}
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"cheerio": "^1.
|
|
25
|
+
"cheerio": "^1.2.0",
|
|
26
26
|
"formidable": "^3.5.4",
|
|
27
|
-
"underscore": "^1.13.
|
|
27
|
+
"underscore": "^1.13.8"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"eslint": "^
|
|
30
|
+
"eslint": "^8.57.1",
|
|
31
31
|
"eslint-config-etherpad": "^4.0.4",
|
|
32
|
-
"socket.io-client": "
|
|
33
|
-
"superagent": "^10.
|
|
34
|
-
"typescript": "^5.
|
|
32
|
+
"socket.io-client": "^4.8.3",
|
|
33
|
+
"superagent": "^10.3.0",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"lint": "eslint .",
|
|
38
|
+
"lint:fix": "eslint --fix ."
|
|
35
39
|
},
|
|
36
40
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
41
|
+
"node": ">=18.0.0"
|
|
38
42
|
},
|
|
39
43
|
"repository": {
|
|
40
44
|
"type": "git",
|
|
41
|
-
"url": "https://github.com/ether/
|
|
45
|
+
"url": "https://github.com/ether/ep_comments_page.git"
|
|
42
46
|
},
|
|
43
47
|
"funding": {
|
|
44
48
|
"type": "individual",
|
|
45
49
|
"url": "https://etherpad.org/"
|
|
46
|
-
},
|
|
47
|
-
"bugs": {
|
|
48
|
-
"url": "https://github.com/ether/ether-plugins/issues"
|
|
49
|
-
},
|
|
50
|
-
"homepage": "https://github.com/ether/ether-plugins/tree/main/ep_comments_page#readme",
|
|
51
|
-
"scripts": {
|
|
52
|
-
"lint": "eslint .",
|
|
53
|
-
"lint:fix": "eslint --fix ."
|
|
54
50
|
}
|
|
55
|
-
}
|
|
51
|
+
}
|
package/static/js/index.js
CHANGED
|
@@ -791,7 +791,12 @@ EpComments.prototype.getCommentData = function () {
|
|
|
791
791
|
|
|
792
792
|
// Delete a pad comment
|
|
793
793
|
EpComments.prototype.deleteComment = function (commentId) {
|
|
794
|
-
$('iframe[name="ace_outer"]').contents().find(`#${commentId}`).
|
|
794
|
+
while ($('iframe[name="ace_outer"]').contents().find(`#${commentId}`).length > 0) {
|
|
795
|
+
$('iframe[name="ace_outer"]').contents().find(`#${commentId}`).remove();
|
|
796
|
+
}
|
|
797
|
+
while ($('iframe[name="ace_outer"]').contents().find(`#icon-${commentId}`).length > 0) {
|
|
798
|
+
$('iframe[name="ace_outer"]').contents().find(`#icon-${commentId}`).remove();
|
|
799
|
+
}
|
|
795
800
|
};
|
|
796
801
|
|
|
797
802
|
const cloneLine = (line) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const common = require('ep_etherpad-lite/tests/backend/common');
|
|
4
|
+
const generateJWTToken = common.generateJWTToken;
|
|
4
5
|
const io = require('socket.io-client');
|
|
5
6
|
const utils = require('../../../utils');
|
|
6
7
|
const createPad = utils.createPad;
|
|
@@ -14,7 +15,6 @@ const codeToBe4 = utils.codeToBe4;
|
|
|
14
15
|
|
|
15
16
|
let api;
|
|
16
17
|
let appUrl;
|
|
17
|
-
const apiKey = common.apiKey;
|
|
18
18
|
|
|
19
19
|
describe(__filename, function () {
|
|
20
20
|
before(async function () {
|
|
@@ -32,32 +32,35 @@ describe(__filename, function () {
|
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it('
|
|
36
|
-
api.get(listCommentRepliesEndPointFor(padID))
|
|
35
|
+
it('returns code 4 if authorization header is missing', async function () {
|
|
36
|
+
await api.get(listCommentRepliesEndPointFor(padID))
|
|
37
37
|
.expect(codeToBe4)
|
|
38
38
|
.expect('Content-Type', /json/)
|
|
39
|
-
.expect(401
|
|
39
|
+
.expect(401);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it('returns code 4 if
|
|
43
|
-
api.get(listCommentRepliesEndPointFor(padID
|
|
42
|
+
it('returns code 4 if authorization header is wrong', async function () {
|
|
43
|
+
await api.get(listCommentRepliesEndPointFor(padID))
|
|
44
|
+
.set('Authorization', 'Bearer wrongtoken')
|
|
44
45
|
.expect(codeToBe4)
|
|
45
46
|
.expect('Content-Type', /json/)
|
|
46
|
-
.expect(401
|
|
47
|
+
.expect(401);
|
|
47
48
|
});
|
|
48
49
|
|
|
49
|
-
it('returns code 0 if
|
|
50
|
-
api.get(listCommentRepliesEndPointFor(padID
|
|
50
|
+
it('returns code 0 if properly authorized', async function () {
|
|
51
|
+
await api.get(listCommentRepliesEndPointFor(padID))
|
|
52
|
+
.set('Authorization', await generateJWTToken())
|
|
51
53
|
.expect(codeToBe0)
|
|
52
54
|
.expect('Content-Type', /json/)
|
|
53
|
-
.expect(200
|
|
55
|
+
.expect(200);
|
|
54
56
|
});
|
|
55
57
|
|
|
56
58
|
it('returns a list of comment replies', function (done) {
|
|
57
59
|
// add a comment to a pad
|
|
58
60
|
createComment(padID, {}, (err, comment) => {
|
|
59
|
-
createCommentReply(padID, comment, {}, (err, replyId) => {
|
|
60
|
-
api.get(listCommentRepliesEndPointFor(padID
|
|
61
|
+
createCommentReply(padID, comment, {}, async (err, replyId) => {
|
|
62
|
+
api.get(listCommentRepliesEndPointFor(padID))
|
|
63
|
+
.set('Authorization', await generateJWTToken())
|
|
61
64
|
.expect((res) => {
|
|
62
65
|
if (res.body.data.replies === undefined) {
|
|
63
66
|
throw new Error('Response expected to have a list of comment replies');
|
|
@@ -84,8 +87,9 @@ describe(__filename, function () {
|
|
|
84
87
|
name,
|
|
85
88
|
timestamp,
|
|
86
89
|
};
|
|
87
|
-
createCommentReply(padID, comment, data, (err, replyId) => {
|
|
88
|
-
api.get(listCommentRepliesEndPointFor(padID
|
|
90
|
+
createCommentReply(padID, comment, data, async (err, replyId) => {
|
|
91
|
+
api.get(listCommentRepliesEndPointFor(padID))
|
|
92
|
+
.set('Authorization', await generateJWTToken())
|
|
89
93
|
.expect((res) => {
|
|
90
94
|
const commentReplyData = res.body.data.replies[replyId];
|
|
91
95
|
if (commentReplyData.commentId !== comment) {
|
|
@@ -121,15 +125,17 @@ describe(__filename, function () {
|
|
|
121
125
|
// create comment
|
|
122
126
|
createComment(padID, {}, (err, comment) => {
|
|
123
127
|
// create reply
|
|
124
|
-
createCommentReply(padID, comment, {}, (err, commentId) => {
|
|
128
|
+
createCommentReply(padID, comment, {}, async (err, commentId) => {
|
|
125
129
|
// get r-w data
|
|
126
|
-
api.get(listCommentRepliesEndPointFor(padID
|
|
130
|
+
api.get(listCommentRepliesEndPointFor(padID))
|
|
131
|
+
.set('Authorization', await generateJWTToken())
|
|
127
132
|
.end((err, res) => {
|
|
128
133
|
const rwData = JSON.stringify(res.body.data);
|
|
129
134
|
// get read-only pad id
|
|
130
|
-
readOnlyId(padID, (err, roPadId) => {
|
|
135
|
+
readOnlyId(padID, async (err, roPadId) => {
|
|
131
136
|
// get r-o data
|
|
132
|
-
api.get(listCommentRepliesEndPointFor(roPadId
|
|
137
|
+
api.get(listCommentRepliesEndPointFor(roPadId))
|
|
138
|
+
.set('Authorization', await generateJWTToken())
|
|
133
139
|
.expect((res) => {
|
|
134
140
|
const roData = JSON.stringify(res.body.data);
|
|
135
141
|
if (roData !== rwData) {
|
|
@@ -163,67 +169,66 @@ describe(__filename, function () {
|
|
|
163
169
|
});
|
|
164
170
|
});
|
|
165
171
|
|
|
166
|
-
it('returns code 1 if data is missing', function (
|
|
167
|
-
api.post(commentRepliesEndPointFor(padID))
|
|
168
|
-
.
|
|
172
|
+
it('returns code 1 if data is missing', async function () {
|
|
173
|
+
await api.post(commentRepliesEndPointFor(padID))
|
|
174
|
+
.set('Authorization', await generateJWTToken())
|
|
169
175
|
.expect(codeToBe1)
|
|
170
176
|
.expect('Content-Type', /json/)
|
|
171
|
-
.expect(200
|
|
177
|
+
.expect(200);
|
|
172
178
|
});
|
|
173
179
|
|
|
174
|
-
it('returns code 1 if data is not a JSON', function (
|
|
175
|
-
api.post(commentRepliesEndPointFor(padID))
|
|
176
|
-
.
|
|
180
|
+
it('returns code 1 if data is not a JSON', async function () {
|
|
181
|
+
await api.post(commentRepliesEndPointFor(padID))
|
|
182
|
+
.set('Authorization', await generateJWTToken())
|
|
177
183
|
.field('data', 'not a JSON')
|
|
178
184
|
.expect(codeToBe1)
|
|
179
185
|
.expect('Content-Type', /json/)
|
|
180
|
-
.expect(200
|
|
186
|
+
.expect(200);
|
|
181
187
|
});
|
|
182
188
|
|
|
183
|
-
it('returns code 4 if
|
|
184
|
-
api.post(commentRepliesEndPointFor(padID))
|
|
189
|
+
it('returns code 4 if authorization header is missing', async function () {
|
|
190
|
+
await api.post(commentRepliesEndPointFor(padID))
|
|
185
191
|
.expect(codeToBe4)
|
|
186
192
|
.expect('Content-Type', /json/)
|
|
187
|
-
.expect(401
|
|
193
|
+
.expect(401);
|
|
188
194
|
});
|
|
189
195
|
|
|
190
|
-
it('returns code 4 if
|
|
191
|
-
api.post(commentRepliesEndPointFor(padID))
|
|
192
|
-
.
|
|
196
|
+
it('returns code 4 if authorization header is wrong', async function () {
|
|
197
|
+
await api.post(commentRepliesEndPointFor(padID))
|
|
198
|
+
.set('Authorization', 'Bearer wrongtoken')
|
|
193
199
|
.expect(codeToBe4)
|
|
194
200
|
.expect('Content-Type', /json/)
|
|
195
|
-
.expect(401
|
|
201
|
+
.expect(401);
|
|
196
202
|
});
|
|
197
203
|
|
|
198
|
-
it('returns code 0 when reply is successfully added', function (
|
|
199
|
-
api.post(commentRepliesEndPointFor(padID))
|
|
200
|
-
.
|
|
204
|
+
it('returns code 0 when reply is successfully added', async function () {
|
|
205
|
+
await api.post(commentRepliesEndPointFor(padID))
|
|
206
|
+
.set('Authorization', await generateJWTToken())
|
|
201
207
|
.field('data', repliesData([replyData(commentID)]))
|
|
202
208
|
.expect(codeToBe0)
|
|
203
209
|
.expect('Content-Type', /json/)
|
|
204
|
-
.expect(200
|
|
210
|
+
.expect(200);
|
|
205
211
|
});
|
|
206
212
|
|
|
207
|
-
it('returns reply ids when replies are successfully added', function (
|
|
213
|
+
it('returns reply ids when replies are successfully added', async function () {
|
|
208
214
|
const twoReplies = repliesData([replyData(), replyData()]);
|
|
209
|
-
api.post(commentRepliesEndPointFor(padID))
|
|
210
|
-
.
|
|
215
|
+
await api.post(commentRepliesEndPointFor(padID))
|
|
216
|
+
.set('Authorization', await generateJWTToken())
|
|
211
217
|
.field('data', twoReplies)
|
|
212
218
|
.expect((res) => {
|
|
213
219
|
if (res.body.replyIds === undefined) throw new Error('Response should have replyIds.');
|
|
214
220
|
if (res.body.replyIds.length !== 2) {
|
|
215
221
|
throw new Error('Response should have two reply ids.');
|
|
216
222
|
}
|
|
217
|
-
})
|
|
218
|
-
.end(done);
|
|
223
|
+
});
|
|
219
224
|
});
|
|
220
225
|
|
|
221
226
|
context('when pad already have replies', function () {
|
|
222
227
|
it('returns only the new reply ids', function (done) {
|
|
223
|
-
createCommentReply(padID, commentID, {}, (err, touch) => {
|
|
228
|
+
createCommentReply(padID, commentID, {}, async (err, touch) => {
|
|
224
229
|
const twoReplies = repliesData([replyData(), replyData()]);
|
|
225
230
|
api.post(commentRepliesEndPointFor(padID))
|
|
226
|
-
.
|
|
231
|
+
.set('Authorization', await generateJWTToken())
|
|
227
232
|
.field('data', twoReplies)
|
|
228
233
|
.expect((res) => {
|
|
229
234
|
if (res.body.replyIds === undefined) {
|
|
@@ -239,15 +244,16 @@ describe(__filename, function () {
|
|
|
239
244
|
});
|
|
240
245
|
});
|
|
241
246
|
|
|
242
|
-
|
|
247
|
+
// These tests rely on socket.io broadcasts that only work when Etherpad
|
|
248
|
+
// is started with loadTest mode enabled. We don't enable loadTest in normal
|
|
249
|
+
// CI (it's only enabled in the periodic load test cron job), so skip them
|
|
250
|
+
// here to keep regular PR CI green.
|
|
251
|
+
(process.env.LOAD_TEST ? describe : describe.skip)('create comment reply API broadcast', () => {
|
|
243
252
|
let padID;
|
|
244
253
|
let commentID;
|
|
245
254
|
let timesMessageWasReceived;
|
|
246
255
|
let socket;
|
|
247
256
|
|
|
248
|
-
// NOTE: this hook will timeout if you don't run your Etherpad in
|
|
249
|
-
// loadTest mode. Be sure to adjust your settings.json when running
|
|
250
|
-
// this test suite
|
|
251
257
|
beforeEach(function (done) {
|
|
252
258
|
timesMessageWasReceived = 0;
|
|
253
259
|
|
|
@@ -329,12 +335,8 @@ describe(__filename, function () {
|
|
|
329
335
|
});
|
|
330
336
|
});
|
|
331
337
|
|
|
332
|
-
const listCommentRepliesEndPointFor = function (padID
|
|
333
|
-
|
|
334
|
-
if (apiKey) {
|
|
335
|
-
extraParams = `?apikey=${apiKey}`;
|
|
336
|
-
}
|
|
337
|
-
return commentRepliesEndPointFor(padID) + extraParams;
|
|
338
|
+
const listCommentRepliesEndPointFor = function (padID) {
|
|
339
|
+
return commentRepliesEndPointFor(padID);
|
|
338
340
|
};
|
|
339
341
|
|
|
340
342
|
const repliesData = function (replies) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const common = require('ep_etherpad-lite/tests/backend/common');
|
|
4
|
+
const generateJWTToken = common.generateJWTToken;
|
|
4
5
|
const io = require('socket.io-client');
|
|
5
6
|
const utils = require('../../../utils');
|
|
6
7
|
const createPad = utils.createPad;
|
|
@@ -13,7 +14,6 @@ const commentsEndPointFor = utils.commentsEndPointFor;
|
|
|
13
14
|
|
|
14
15
|
let api;
|
|
15
16
|
let appUrl;
|
|
16
|
-
const apiKey = common.apiKey;
|
|
17
17
|
|
|
18
18
|
describe(__filename, function () {
|
|
19
19
|
before(async function () {
|
|
@@ -32,34 +32,37 @@ describe(__filename, function () {
|
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it('returns code 4 if
|
|
36
|
-
api.get(listCommentsEndPointFor(padID))
|
|
35
|
+
it('returns code 4 if authorization header is missing', async function () {
|
|
36
|
+
await api.get(listCommentsEndPointFor(padID))
|
|
37
37
|
.expect(codeToBe4)
|
|
38
38
|
.expect('Content-Type', /json/)
|
|
39
|
-
.expect(401
|
|
39
|
+
.expect(401);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it('returns code 4 if
|
|
43
|
-
api.get(listCommentsEndPointFor(padID
|
|
42
|
+
it('returns code 4 if authorization header is wrong', async function () {
|
|
43
|
+
await api.get(listCommentsEndPointFor(padID))
|
|
44
|
+
.set('Authorization', 'Bearer wrongtoken')
|
|
44
45
|
.expect(codeToBe4)
|
|
45
46
|
.expect('Content-Type', /json/)
|
|
46
|
-
.expect(401
|
|
47
|
+
.expect(401);
|
|
47
48
|
});
|
|
48
49
|
|
|
49
|
-
it('returns code 0 when
|
|
50
|
-
api.get(listCommentsEndPointFor(padID
|
|
50
|
+
it('returns code 0 when properly authorized', async function () {
|
|
51
|
+
await api.get(listCommentsEndPointFor(padID))
|
|
52
|
+
.set('Authorization', await generateJWTToken())
|
|
51
53
|
.expect(codeToBe0)
|
|
52
54
|
.expect('Content-Type', /json/)
|
|
53
|
-
.expect(200
|
|
55
|
+
.expect(200);
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
it('returns comment list when
|
|
58
|
+
it('returns comment list when properly authorized', function (done) {
|
|
57
59
|
// creates first comment...
|
|
58
60
|
createComment(padID, {}, (err, comment) => {
|
|
59
61
|
// ... creates second comment...
|
|
60
|
-
createComment(padID, {}, (err, comment) => {
|
|
62
|
+
createComment(padID, {}, async (err, comment) => {
|
|
61
63
|
// ... and finally checks if comments are returned
|
|
62
|
-
api.get(listCommentsEndPointFor(padID
|
|
64
|
+
api.get(listCommentsEndPointFor(padID))
|
|
65
|
+
.set('Authorization', await generateJWTToken())
|
|
63
66
|
.expect((res) => {
|
|
64
67
|
if (res.body.data.comments === undefined) {
|
|
65
68
|
throw new Error('Response should have list of comments.');
|
|
@@ -85,8 +88,9 @@ describe(__filename, function () {
|
|
|
85
88
|
changeTo,
|
|
86
89
|
changeFrom,
|
|
87
90
|
};
|
|
88
|
-
createComment(padID, data, (err, commentId) => {
|
|
89
|
-
api.get(listCommentsEndPointFor(padID
|
|
91
|
+
createComment(padID, data, async (err, commentId) => {
|
|
92
|
+
api.get(listCommentsEndPointFor(padID))
|
|
93
|
+
.set('Authorization', await generateJWTToken())
|
|
90
94
|
.expect((res) => {
|
|
91
95
|
const commentData = res.body.data.comments[commentId];
|
|
92
96
|
if (commentData.name !== name) {
|
|
@@ -113,12 +117,14 @@ describe(__filename, function () {
|
|
|
113
117
|
});
|
|
114
118
|
|
|
115
119
|
it('returns same data for read-write and read-only pad ids', function (done) {
|
|
116
|
-
createComment(padID, {}, (err, commentId) => {
|
|
117
|
-
api.get(listCommentsEndPointFor(padID
|
|
120
|
+
createComment(padID, {}, async (err, commentId) => {
|
|
121
|
+
api.get(listCommentsEndPointFor(padID))
|
|
122
|
+
.set('Authorization', await generateJWTToken())
|
|
118
123
|
.end((err, res) => {
|
|
119
124
|
const rwData = JSON.stringify(res.body.data);
|
|
120
|
-
readOnlyId(padID, (err, roPadId) => {
|
|
121
|
-
api.get(listCommentsEndPointFor(roPadId
|
|
125
|
+
readOnlyId(padID, async (err, roPadId) => {
|
|
126
|
+
api.get(listCommentsEndPointFor(roPadId))
|
|
127
|
+
.set('Authorization', await generateJWTToken())
|
|
122
128
|
.expect((res) => {
|
|
123
129
|
const roData = JSON.stringify(res.body.data);
|
|
124
130
|
if (roData !== rwData) {
|
|
@@ -144,53 +150,53 @@ describe(__filename, function () {
|
|
|
144
150
|
});
|
|
145
151
|
});
|
|
146
152
|
|
|
147
|
-
it('returns code 1 if data is missing', function (
|
|
148
|
-
api.post(commentsEndPointFor(padID))
|
|
149
|
-
.
|
|
153
|
+
it('returns code 1 if data is missing', async function () {
|
|
154
|
+
await api.post(commentsEndPointFor(padID))
|
|
155
|
+
.set('Authorization', await generateJWTToken())
|
|
150
156
|
.expect(codeToBe1)
|
|
151
157
|
.expect('Content-Type', /json/)
|
|
152
|
-
.expect(200
|
|
158
|
+
.expect(200);
|
|
153
159
|
});
|
|
154
160
|
|
|
155
|
-
it('returns code 1 if data is not a JSON', function (
|
|
156
|
-
api.post(commentsEndPointFor(padID))
|
|
157
|
-
.
|
|
161
|
+
it('returns code 1 if data is not a JSON', async function () {
|
|
162
|
+
await api.post(commentsEndPointFor(padID))
|
|
163
|
+
.set('Authorization', await generateJWTToken())
|
|
158
164
|
.field('data', 'not a JSON')
|
|
159
165
|
.expect(codeToBe1)
|
|
160
166
|
.expect('Content-Type', /json/)
|
|
161
|
-
.expect(200
|
|
167
|
+
.expect(200);
|
|
162
168
|
});
|
|
163
169
|
|
|
164
|
-
it('returns code 4 if
|
|
165
|
-
api.post(commentsEndPointFor(padID))
|
|
170
|
+
it('returns code 4 if authorization header is missing', async function () {
|
|
171
|
+
await api.post(commentsEndPointFor(padID))
|
|
166
172
|
.field('data', commentsData())
|
|
167
173
|
.expect(codeToBe4)
|
|
168
174
|
.expect('Content-Type', /json/)
|
|
169
|
-
.expect(401
|
|
175
|
+
.expect(401);
|
|
170
176
|
});
|
|
171
177
|
|
|
172
|
-
it('returns code 4 if
|
|
173
|
-
api.post(commentsEndPointFor(padID))
|
|
174
|
-
.
|
|
178
|
+
it('returns code 4 if authorization header is wrong', async function () {
|
|
179
|
+
await api.post(commentsEndPointFor(padID))
|
|
180
|
+
.set('Authorization', 'Bearer wrongtoken')
|
|
175
181
|
.field('data', commentsData())
|
|
176
182
|
.expect(codeToBe4)
|
|
177
183
|
.expect('Content-Type', /json/)
|
|
178
|
-
.expect(401
|
|
184
|
+
.expect(401);
|
|
179
185
|
});
|
|
180
186
|
|
|
181
|
-
it('returns code 0 when comment is successfully added', function (
|
|
182
|
-
api.post(commentsEndPointFor(padID))
|
|
183
|
-
.
|
|
187
|
+
it('returns code 0 when comment is successfully added', async function () {
|
|
188
|
+
await api.post(commentsEndPointFor(padID))
|
|
189
|
+
.set('Authorization', await generateJWTToken())
|
|
184
190
|
.field('data', commentsData())
|
|
185
191
|
.expect(codeToBe0)
|
|
186
192
|
.expect('Content-Type', /json/)
|
|
187
|
-
.expect(200
|
|
193
|
+
.expect(200);
|
|
188
194
|
});
|
|
189
195
|
|
|
190
|
-
it('returns comment ids when comment is successfully added', function (
|
|
196
|
+
it('returns comment ids when comment is successfully added', async function () {
|
|
191
197
|
const twoComments = commentsData([commentData(), commentData()]);
|
|
192
|
-
api.post(commentsEndPointFor(padID))
|
|
193
|
-
.
|
|
198
|
+
await api.post(commentsEndPointFor(padID))
|
|
199
|
+
.set('Authorization', await generateJWTToken())
|
|
194
200
|
.field('data', twoComments)
|
|
195
201
|
.expect((res) => {
|
|
196
202
|
if (res.body.commentIds === undefined) {
|
|
@@ -199,16 +205,15 @@ describe(__filename, function () {
|
|
|
199
205
|
if (res.body.commentIds.length !== 2) {
|
|
200
206
|
throw new Error('Response should have two comment ids.');
|
|
201
207
|
}
|
|
202
|
-
})
|
|
203
|
-
.end(done);
|
|
208
|
+
});
|
|
204
209
|
});
|
|
205
210
|
|
|
206
211
|
context('when pad already have comments', function () {
|
|
207
212
|
it('returns only the new comment ids', function (done) {
|
|
208
|
-
createComment(padID, {}, (err, touch) => {
|
|
213
|
+
createComment(padID, {}, async (err, touch) => {
|
|
209
214
|
const twoComments = commentsData([commentData(), commentData()]);
|
|
210
215
|
api.post(commentsEndPointFor(padID))
|
|
211
|
-
.
|
|
216
|
+
.set('Authorization', await generateJWTToken())
|
|
212
217
|
.field('data', twoComments)
|
|
213
218
|
.expect((res) => {
|
|
214
219
|
if (res.body.commentIds === undefined) {
|
|
@@ -224,14 +229,15 @@ describe(__filename, function () {
|
|
|
224
229
|
});
|
|
225
230
|
});
|
|
226
231
|
|
|
227
|
-
|
|
232
|
+
// These tests rely on socket.io broadcasts that only work when Etherpad
|
|
233
|
+
// is started with loadTest mode enabled. We don't enable loadTest in normal
|
|
234
|
+
// CI (it's only enabled in the periodic load test cron job), so skip them
|
|
235
|
+
// here to keep regular PR CI green.
|
|
236
|
+
(process.env.LOAD_TEST ? describe : describe.skip)('create comment API broadcast', () => {
|
|
228
237
|
let padID;
|
|
229
238
|
let timesMessageWasReceived;
|
|
230
239
|
let socket;
|
|
231
240
|
|
|
232
|
-
// NOTE: this hook will timeout if you don't run your Etherpad in
|
|
233
|
-
// loadTest mode. Be sure to adjust your settings.json when running
|
|
234
|
-
// this test suite
|
|
235
241
|
beforeEach(function (done) {
|
|
236
242
|
timesMessageWasReceived = 0;
|
|
237
243
|
|
|
@@ -302,12 +308,8 @@ describe(__filename, function () {
|
|
|
302
308
|
});
|
|
303
309
|
});
|
|
304
310
|
|
|
305
|
-
const listCommentsEndPointFor = function (padID
|
|
306
|
-
|
|
307
|
-
if (apiKey) {
|
|
308
|
-
extraParams = `?apikey=${apiKey}`;
|
|
309
|
-
}
|
|
310
|
-
return commentsEndPointFor(padID) + extraParams;
|
|
311
|
+
const listCommentsEndPointFor = function (padID) {
|
|
312
|
+
return commentsEndPointFor(padID);
|
|
311
313
|
};
|
|
312
314
|
|
|
313
315
|
const commentsData = function (comments) {
|
|
@@ -6,13 +6,18 @@
|
|
|
6
6
|
|
|
7
7
|
const assert = require('assert').strict;
|
|
8
8
|
const common = require('ep_etherpad-lite/tests/backend/common');
|
|
9
|
+
const generateJWTToken = common.generateJWTToken;
|
|
9
10
|
const superagent = require('superagent');
|
|
10
11
|
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
11
13
|
|
|
12
|
-
// test doc
|
|
13
|
-
|
|
14
|
+
// test doc — kept under ../../fixtures/ rather than alongside this spec
|
|
15
|
+
// because etherpad-lite's mocha glob is `static/tests/backend/specs/**` (no
|
|
16
|
+
// extension filter), so any non-JS file inside specs/ trips the ESM loader
|
|
17
|
+
// with `ERR_UNKNOWN_FILE_EXTENSION`. Fixtures must live OUTSIDE specs/.
|
|
18
|
+
const etherpadDoc = fs.readFileSync(
|
|
19
|
+
path.join(__dirname, '..', '..', 'fixtures', 'test.etherpad'));
|
|
14
20
|
const apiVersion = 1;
|
|
15
|
-
const apiKey = common.apiKey;
|
|
16
21
|
const testPadId = makeid();
|
|
17
22
|
let api;
|
|
18
23
|
|
|
@@ -22,12 +27,14 @@ describe(__filename, function () {
|
|
|
22
27
|
describe('Imports and Exports', function () {
|
|
23
28
|
it('creates a new Pad, imports content to it, checks that content', async function () {
|
|
24
29
|
await api.get(`${endPoint('createPad')}&padID=${testPadId}`)
|
|
30
|
+
.set('Authorization', await generateJWTToken())
|
|
25
31
|
.expect(200)
|
|
26
32
|
.expect('Content-Type', /json/);
|
|
27
33
|
});
|
|
28
34
|
|
|
29
35
|
it('imports .etherpad incuding a comment', async function () {
|
|
30
36
|
await api.post(`/p/${testPadId}/import`)
|
|
37
|
+
.set('Authorization', await generateJWTToken())
|
|
31
38
|
.attach('file', etherpadDoc, {
|
|
32
39
|
filename: '/test.etherpad',
|
|
33
40
|
contentType: 'application/etherpad',
|
|
@@ -39,6 +46,7 @@ describe(__filename, function () {
|
|
|
39
46
|
|
|
40
47
|
it('exports .etherpad and checks it includes comments', async function () {
|
|
41
48
|
await api.get(`/p/${testPadId}/export/etherpad`)
|
|
49
|
+
.set('Authorization', await generateJWTToken())
|
|
42
50
|
.buffer(true).parse(superagent.parse.text)
|
|
43
51
|
.expect(200)
|
|
44
52
|
.expect(/comments:/);
|
|
@@ -49,7 +57,7 @@ describe(__filename, function () {
|
|
|
49
57
|
|
|
50
58
|
const endPoint = function (point, version) {
|
|
51
59
|
version = version || apiVersion;
|
|
52
|
-
return `/api/${version}/${point}
|
|
60
|
+
return `/api/${version}/${point}?`;
|
|
53
61
|
};
|
|
54
62
|
|
|
55
63
|
function makeid() {
|