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.
@@ -4,12 +4,12 @@ const utils = require('../../../utils');
4
4
  const codeToBe0 = utils.codeToBe0;
5
5
  const apiVersion = utils.apiVersion;
6
6
  const randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
7
- import settings from 'ep_etherpad-lite/node/utils/Settings'
7
+ const settings = require('ep_etherpad-lite/node/utils/Settings');
8
8
  const common = require('ep_etherpad-lite/tests/backend/common');
9
+ const generateJWTToken = common.generateJWTToken;
9
10
  const db = require('ep_etherpad-lite/node/db/DB');
10
11
 
11
12
  let agent;
12
- const apiKey = common.apiKey;
13
13
 
14
14
  describe(__filename, function () {
15
15
  let padID;
@@ -19,11 +19,13 @@ describe(__filename, function () {
19
19
 
20
20
  beforeEach(async function () {
21
21
  padID = randomString(5);
22
- await agent.get(`/api/${apiVersion}/createPad?apikey=${apiKey}&padID=${padID}`)
22
+ await agent.get(`/api/${apiVersion}/createPad?padID=${padID}`)
23
+ .set('Authorization', await generateJWTToken())
23
24
  .expect(200)
24
25
  .expect('Content-Type', /json/)
25
26
  .expect(codeToBe0);
26
- await agent.get(`/api/${apiVersion}/setHTML?apikey=${apiKey}&padID=${padID}&html=${html()}`)
27
+ await agent.get(`/api/${apiVersion}/setHTML?padID=${padID}&html=${html()}`)
28
+ .set('Authorization', await generateJWTToken())
27
29
  .expect(200)
28
30
  .expect('Content-Type', /json/)
29
31
  .expect(codeToBe0);
@@ -35,7 +37,8 @@ describe(__filename, function () {
35
37
  });
36
38
 
37
39
  it('returns ok', async function () {
38
- agent.get(getHTMLEndPointFor(padID))
40
+ await agent.get(getHTMLEndPointFor(padID))
41
+ .set('Authorization', await generateJWTToken())
39
42
  .expect(codeToBe0)
40
43
  .expect('Content-Type', /json/)
41
44
  .expect(200);
@@ -43,7 +46,8 @@ describe(__filename, function () {
43
46
 
44
47
  it('returns HTML with comment class', async function () {
45
48
  await insertCommentToDB(padID, 'c-1234');
46
- agent.get(getHTMLEndPointFor(padID))
49
+ await agent.get(getHTMLEndPointFor(padID))
50
+ .set('Authorization', await generateJWTToken())
47
51
  .expect((res) => {
48
52
  const expectedRegex = regexWithComment('c-1234');
49
53
  const expectedComments = new RegExp(expectedRegex);
@@ -64,7 +68,8 @@ describe(__filename, function () {
64
68
  it('returns HTML with two comments spans', async function () {
65
69
  await insertCommentToDB(padID, 'c-1234');
66
70
  await insertCommentToDB(padID, 'c-82a3');
67
- agent.get(getHTMLEndPointFor(padID))
71
+ await agent.get(getHTMLEndPointFor(padID))
72
+ .set('Authorization', await generateJWTToken())
68
73
  .expect((res) => {
69
74
  const firstComment = regexWithComment('c-1234');
70
75
  const secondComment = regexWithComment('c-82a3');
@@ -86,8 +91,9 @@ describe(__filename, function () {
86
91
  html = () => buildHTML('empty pad');
87
92
  });
88
93
 
89
- it('returns HTML with no comment', function (done) {
90
- agent.get(getHTMLEndPointFor(padID))
94
+ it('returns HTML with no comment', async function () {
95
+ await agent.get(getHTMLEndPointFor(padID))
96
+ .set('Authorization', await generateJWTToken())
91
97
  .expect((res) => {
92
98
  const expectedRegex = '.*empty pad.*';
93
99
  const noComment = new RegExp(expectedRegex);
@@ -98,8 +104,7 @@ describe(__filename, function () {
98
104
  throw new Error('Comment exported, should not have any. ' +
99
105
  `Regex used: ${expectedRegex}, html exported: ${html}`);
100
106
  }
101
- })
102
- .end(done);
107
+ });
103
108
  });
104
109
  });
105
110
 
@@ -111,8 +116,9 @@ describe(__filename, function () {
111
116
 
112
117
  // Etherpad exports tags using the order they are defined on the array (bold is always inside
113
118
  // comment)
114
- xit('returns HTML with strong and comment, in any order', function (done) {
115
- agent.get(getHTMLEndPointFor(padID))
119
+ xit('returns HTML with strong and comment, in any order', async function () {
120
+ await agent.get(getHTMLEndPointFor(padID))
121
+ .set('Authorization', await generateJWTToken())
116
122
  .expect(200)
117
123
  .expect('Content-Type', /json/)
118
124
  .expect(codeToBe0)
@@ -132,8 +138,7 @@ describe(__filename, function () {
132
138
  `[${strongInsideCommentRegex} || ${commentInsideStrongRegex}], ` +
133
139
  `html exported: ${html}`);
134
140
  }
135
- })
136
- .end(done);
141
+ });
137
142
  });
138
143
  });
139
144
 
@@ -146,16 +151,16 @@ describe(__filename, function () {
146
151
 
147
152
  // Etherpad exports tags using the order they are defined on the array (bold is always inside
148
153
  // comment)
149
- it('returns HTML with strong and comment, in any order', function (done) {
150
- agent.get(getHTMLEndPointFor(padID))
154
+ it('returns HTML with strong and comment, in any order', async function () {
155
+ await agent.get(getHTMLEndPointFor(padID))
156
+ .set('Authorization', await generateJWTToken())
151
157
  .expect((res) => {
152
158
  const html = res.body.data.html;
153
159
  const foundComment = (html.indexOf('<strong>') !== -1);
154
160
  if (!foundComment) {
155
161
  throw new Error(`Comment not exported. Regex used: <strong>, html exported: ${html}`);
156
162
  }
157
- })
158
- .end(done);
163
+ });
159
164
  });
160
165
  });
161
166
 
@@ -166,7 +171,8 @@ describe(__filename, function () {
166
171
 
167
172
  it('returns HTML with part with comment and part without it', async function () {
168
173
  await insertCommentToDB(padID, 'c-2342');
169
- agent.get(getHTMLEndPointFor(padID))
174
+ await agent.get(getHTMLEndPointFor(padID))
175
+ .set('Authorization', await generateJWTToken())
170
176
  .expect((res) => {
171
177
  const expectedRegex = `no comment here ${regexWithComment('c-2342')}`;
172
178
  const expectedComments = new RegExp(expectedRegex);
@@ -188,7 +194,8 @@ describe(__filename, function () {
188
194
 
189
195
  it('returns ok', async function () {
190
196
  settings.ep_comments_page = {exportHTML: false};
191
- agent.get(getHTMLEndPointFor(padID))
197
+ await agent.get(getHTMLEndPointFor(padID))
198
+ .set('Authorization', await generateJWTToken())
192
199
  .expect(codeToBe0)
193
200
  .expect('Content-Type', /json/)
194
201
  .expect(200);
@@ -196,7 +203,8 @@ describe(__filename, function () {
196
203
 
197
204
  it('returns HTML without comment class', async function () {
198
205
  settings.ep_comments_page = {exportHtml: false};
199
- agent.get(getHTMLEndPointFor(padID))
206
+ await agent.get(getHTMLEndPointFor(padID))
207
+ .set('Authorization', await generateJWTToken())
200
208
  .expect((res) => {
201
209
  const expectedRegex = regexWithComment('c-1234');
202
210
  const expectedComments = new RegExp(expectedRegex);
@@ -217,7 +225,8 @@ describe(__filename, function () {
217
225
 
218
226
  it('returns ok', async function () {
219
227
  settings.ep_comments_page = {exportHTML: true};
220
- agent.get(getHTMLEndPointFor(padID))
228
+ await agent.get(getHTMLEndPointFor(padID))
229
+ .set('Authorization', await generateJWTToken())
221
230
  .expect(codeToBe0)
222
231
  .expect('Content-Type', /json/)
223
232
  .expect(200);
@@ -226,7 +235,8 @@ describe(__filename, function () {
226
235
  it('returns HTML with comment class', async function () {
227
236
  settings.ep_comments_page = {exportHtml: true};
228
237
  await insertCommentToDB(padID, 'c-1234');
229
- agent.get(getHTMLEndPointFor(padID))
238
+ await agent.get(getHTMLEndPointFor(padID))
239
+ .set('Authorization', await generateJWTToken())
230
240
  .expect((res) => {
231
241
  const expectedRegex = regexWithComment('c-1234');
232
242
  const expectedComments = new RegExp(expectedRegex);
@@ -241,7 +251,7 @@ describe(__filename, function () {
241
251
  });
242
252
  });
243
253
 
244
- const getHTMLEndPointFor = (padID) => `/api/${apiVersion}/getHTML?apikey=${apiKey}&padID=${padID}`;
254
+ const getHTMLEndPointFor = (padID) => `/api/${apiVersion}/getHTML?padID=${padID}`;
245
255
 
246
256
  const buildHTML = (body) => `<html><body>${body}</body></html>`;
247
257
 
@@ -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 utils = require('../../utils');
5
6
  const createPad = utils.createPad;
6
7
  const createComment = utils.createComment;
@@ -9,7 +10,6 @@ const commentsEndPointFor = utils.commentsEndPointFor;
9
10
  const commentRepliesEndPointFor = utils.commentRepliesEndPointFor;
10
11
 
11
12
  let api;
12
- const apiKey = common.apiKey;
13
13
 
14
14
  describe(__filename, function () {
15
15
  let padID;
@@ -29,10 +29,10 @@ describe(__filename, function () {
29
29
  if (err) throw err;
30
30
  // ... duplicate pad...
31
31
  const copiedPadID = `${padID}-copy`;
32
- copyPad(padID, copiedPadID, () => {
32
+ copyPad(padID, copiedPadID, async () => {
33
33
  // ... and finally check if comments are returned
34
- const getCommentsRoute = `${commentsEndPointFor(copiedPadID)}?apikey=${apiKey}`;
35
- api.get(getCommentsRoute)
34
+ api.get(commentsEndPointFor(copiedPadID))
35
+ .set('Authorization', await generateJWTToken())
36
36
  .expect((res) => {
37
37
  const commentsFound = Object.keys(res.body.data.comments);
38
38
  if (commentsFound.length !== 1) {
@@ -55,10 +55,10 @@ describe(__filename, function () {
55
55
 
56
56
  // ... duplicate pad...
57
57
  const copiedPadID = `${padID}-copy`;
58
- copyPad(padID, copiedPadID, () => {
58
+ copyPad(padID, copiedPadID, async () => {
59
59
  // ... and finally check if replies are returned
60
- const getRepliesRoute = `${commentRepliesEndPointFor(copiedPadID)}?apikey=${apiKey}`;
61
- api.get(getRepliesRoute)
60
+ api.get(commentRepliesEndPointFor(copiedPadID))
61
+ .set('Authorization', await generateJWTToken())
62
62
  .expect((res) => {
63
63
  const repliesFound = Object.keys(res.body.data.replies);
64
64
  if (repliesFound.length !== 1) {
@@ -72,14 +72,17 @@ describe(__filename, function () {
72
72
  });
73
73
  });
74
74
 
75
- const copyPad = function (originalPadID, copiedPadID, callback) {
75
+ const copyPad = async function (originalPadID, copiedPadID, callback) {
76
76
  const copyPadRoute =
77
- `/api/1.2.9/copyPad?apikey=${apiKey}&sourceID=${originalPadID}&destinationID=${copiedPadID}`;
78
- api.get(copyPadRoute).end((err, res) => {
79
- if (err || res.body.code !== 0) {
80
- throw (err || res.body.message || `unknown error while calling API route ${copyPadRoute}`);
81
- }
77
+ `/api/1.2.9/copyPad?sourceID=${originalPadID}&destinationID=${copiedPadID}`;
78
+ api.get(copyPadRoute)
79
+ .set('Authorization', await generateJWTToken())
80
+ .end((err, res) => {
81
+ if (err || res.body.code !== 0) {
82
+ throw (err || res.body.message ||
83
+ `unknown error while calling API route ${copyPadRoute}`);
84
+ }
82
85
 
83
- callback();
84
- });
86
+ callback();
87
+ });
85
88
  };
@@ -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 utils = require('../../utils');
5
6
  const createPad = utils.createPad;
6
7
  const createComment = utils.createComment;
@@ -9,7 +10,6 @@ const commentsEndPointFor = utils.commentsEndPointFor;
9
10
  const commentRepliesEndPointFor = utils.commentRepliesEndPointFor;
10
11
 
11
12
  let api;
12
- const apiKey = common.apiKey;
13
13
 
14
14
  describe(__filename, function () {
15
15
  let padID;
@@ -28,10 +28,10 @@ describe(__filename, function () {
28
28
  createComment(padID, {}, (err, comment) => {
29
29
  if (err) throw err;
30
30
  // ... remove pad...
31
- deletePad(padID, () => {
31
+ deletePad(padID, async () => {
32
32
  // ... and finally check if comments are returned
33
- const getCommentsRoute = `${commentsEndPointFor(padID)}?apikey=${apiKey}`;
34
- api.get(getCommentsRoute)
33
+ api.get(commentsEndPointFor(padID))
34
+ .set('Authorization', await generateJWTToken())
35
35
  .expect((res) => {
36
36
  const commentsFound = Object.keys(res.body.data.comments);
37
37
  if (commentsFound.length !== 0) {
@@ -54,10 +54,10 @@ describe(__filename, function () {
54
54
  if (err) throw err;
55
55
 
56
56
  // ... remove pad...
57
- deletePad(padID, () => {
57
+ deletePad(padID, async () => {
58
58
  // ... and finally check if replies are returned
59
- const getRepliesRoute = `${commentRepliesEndPointFor(padID)}?apikey=${apiKey}`;
60
- api.get(getRepliesRoute)
59
+ api.get(commentRepliesEndPointFor(padID))
60
+ .set('Authorization', await generateJWTToken())
61
61
  .expect((res) => {
62
62
  const repliesFound = Object.keys(res.body.data.replies);
63
63
  if (repliesFound.length !== 0) {
@@ -72,13 +72,16 @@ describe(__filename, function () {
72
72
  });
73
73
  });
74
74
 
75
- const deletePad = function (padID, callback) {
76
- const deletePadRoute = `/api/1/deletePad?apikey=${apiKey}&padID=${padID}`;
77
- api.get(deletePadRoute).end((err, res) => {
78
- if (err || res.body.code !== 0) {
79
- throw (err || res.body.message || `unknown error while calling API route ${deletePadRoute}`);
80
- }
75
+ const deletePad = async function (padID, callback) {
76
+ const deletePadRoute = `/api/1/deletePad?padID=${padID}`;
77
+ api.get(deletePadRoute)
78
+ .set('Authorization', await generateJWTToken())
79
+ .end((err, res) => {
80
+ if (err || res.body.code !== 0) {
81
+ throw (err || res.body.message ||
82
+ `unknown error while calling API route ${deletePadRoute}`);
83
+ }
81
84
 
82
- callback();
83
- });
85
+ callback();
86
+ });
84
87
  };
@@ -1,11 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const AttributePool = require('ep_etherpad-lite/static/js/AttributePool');
4
- const Changeset = require('ep_etherpad-lite/static/js/Changeset');
3
+ const AttributePool = require('ep_etherpad-lite/static/js/AttributePool').default || require('ep_etherpad-lite/static/js/AttributePool');
4
+ const Changeset = require('ep_etherpad-lite/static/js/Changeset').default || require('ep_etherpad-lite/static/js/Changeset');
5
+ const SmartOpAssemblerModule = require('ep_etherpad-lite/static/js/SmartOpAssembler');
6
+ const SmartOpAssembler = SmartOpAssemblerModule.SmartOpAssembler || SmartOpAssemblerModule.default || SmartOpAssemblerModule;
5
7
  const assert = require('assert').strict;
6
8
  const common = require('ep_etherpad-lite/tests/backend/common');
7
9
  const padManager = require('ep_etherpad-lite/node/db/PadManager');
8
- const readOnlyManager = require('ep_etherpad-lite/node/db/ReadOnlyManager');
10
+ const readOnlyManager = require('ep_etherpad-lite/node/db/ReadOnlyManager').default || require('ep_etherpad-lite/node/db/ReadOnlyManager');
9
11
  const shared = require('../../../js/shared.js');
10
12
 
11
13
  describe(__filename, function () {
@@ -22,7 +24,7 @@ describe(__filename, function () {
22
24
  const op = Changeset.newOp(opcode);
23
25
  op.chars = 1;
24
26
  op.attribs = Changeset.makeAttribsString(opcode, attribs, apool);
25
- const assem = Changeset.smartOpAssembler();
27
+ const assem = new SmartOpAssembler();
26
28
  assem.append(op);
27
29
  const cs = assem.toString();
28
30
  const newLen = oldLen + assem.getLengthChange();
@@ -3,7 +3,7 @@
3
3
  const common = require('ep_etherpad-lite/tests/backend/common');
4
4
  const randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
5
5
 
6
- const apiKey = common.apiKey;
6
+ const generateJWTToken = common.generateJWTToken;
7
7
  const apiVersion = 1;
8
8
 
9
9
  // Functions to validate API responses:
@@ -29,9 +29,10 @@ const commentRepliesEndPointFor = function (pad) {
29
29
 
30
30
  // Creates a pad and returns the pad id. Calls the callback when finished.
31
31
  const createPad = function (done) {
32
- common.init().then((agent) => {
32
+ common.init().then(async (agent) => {
33
33
  const pad = randomString(5);
34
- agent.get(`/api/${apiVersion}/createPad?apikey=${apiKey}&padID=${pad}`)
34
+ agent.get(`/api/${apiVersion}/createPad?padID=${pad}`)
35
+ .set('Authorization', await generateJWTToken())
35
36
  .end((err, res) => {
36
37
  if (err || (res.body.code !== 0)) return done(new Error('Unable to create new Pad'));
37
38
  done(null, pad);
@@ -40,8 +41,9 @@ const createPad = function (done) {
40
41
  };
41
42
 
42
43
  const readOnlyId = function (padID, done) {
43
- common.init().then((agent) => {
44
- agent.get(`/api/${apiVersion}/getReadOnlyID?apikey=${apiKey}&padID=${padID}`)
44
+ common.init().then(async (agent) => {
45
+ agent.get(`/api/${apiVersion}/getReadOnlyID?padID=${padID}`)
46
+ .set('Authorization', await generateJWTToken())
45
47
  .end((err, res) => {
46
48
  if (err || (res.body.code !== 0)) return done(new Error('Unable to get read only id'));
47
49
  done(null, res.body.data.readOnlyID);
@@ -54,10 +56,10 @@ const createComment = function (pad, commentData, done) {
54
56
  commentData = commentData || {};
55
57
  commentData.name = commentData.name || 'John Doe';
56
58
  commentData.text = commentData.text || 'This is a comment';
57
- common.init().then((agent) => {
59
+ common.init().then(async (agent) => {
58
60
  agent.post(commentsEndPointFor(pad))
61
+ .set('Authorization', await generateJWTToken())
59
62
  .send({
60
- apikey: apiKey,
61
63
  data: JSON.stringify([commentData]),
62
64
  })
63
65
  .expect(200)
@@ -76,10 +78,10 @@ const createCommentReply = function (pad, comment, replyData, done) {
76
78
  replyData.commentId = comment;
77
79
  replyData.name = replyData.name || 'John Doe';
78
80
  replyData.text = replyData.text || 'This is a reply';
79
- common.init().then((agent) => {
81
+ common.init().then(async (agent) => {
80
82
  agent.post(commentRepliesEndPointFor(pad))
83
+ .set('Authorization', await generateJWTToken())
81
84
  .send({
82
- apikey: apiKey,
83
85
  data: JSON.stringify([replyData]),
84
86
  })
85
87
  .expect(200)