mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 00:46:16 -04:00
API: Add optional authorId
param to mutation functions
This commit is contained in:
parent
50fafe608b
commit
aa286b7dbd
6 changed files with 93 additions and 42 deletions
|
@ -1,21 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('assert').strict;
|
||||
const authorManager = require('../../../../node/db/AuthorManager');
|
||||
const common = require('../../common');
|
||||
const padManager = require('../../../../node/db/PadManager');
|
||||
|
||||
describe(__filename, function () {
|
||||
let agent;
|
||||
let authorId;
|
||||
let padId;
|
||||
let pad;
|
||||
|
||||
const restoreRevision = async (padId, rev) => {
|
||||
const restoreRevision = async (v, padId, rev, authorId = null) => {
|
||||
const p = new URLSearchParams(Object.entries({
|
||||
apikey: common.apiKey,
|
||||
padID: padId,
|
||||
rev,
|
||||
...(authorId == null ? {} : {authorId}),
|
||||
}));
|
||||
const res = await agent.get(`/api/1.2.11/restoreRevision?${p}`)
|
||||
const res = await agent.get(`/api/${v}/restoreRevision?${p}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/);
|
||||
assert.equal(res.body.code, 0);
|
||||
|
@ -23,6 +26,8 @@ describe(__filename, function () {
|
|||
|
||||
before(async function () {
|
||||
agent = await common.init();
|
||||
authorId = await authorManager.getAuthor4Token('test-restoreRevision');
|
||||
assert(authorId);
|
||||
});
|
||||
|
||||
beforeEach(async function () {
|
||||
|
@ -38,14 +43,39 @@ describe(__filename, function () {
|
|||
if (await padManager.doesPadExist(padId)) await padManager.removePad(padId);
|
||||
});
|
||||
|
||||
// TODO: Enable once the end-of-pad newline bugs are fixed. See:
|
||||
// https://github.com/ether/etherpad-lite/pull/5253
|
||||
xit('content matches', async function () {
|
||||
const oldHead = pad.head;
|
||||
const wantAText = await pad.getInternalRevisionAText(pad.head - 1);
|
||||
assert(wantAText.text.endsWith('\nfoo\n'));
|
||||
await restoreRevision(padId, pad.head - 1);
|
||||
assert.equal(pad.head, oldHead + 1);
|
||||
assert.deepEqual(await pad.getInternalRevisionAText(pad.head), wantAText);
|
||||
describe('v1.2.11', function () {
|
||||
// TODO: Enable once the end-of-pad newline bugs are fixed. See:
|
||||
// https://github.com/ether/etherpad-lite/pull/5253
|
||||
xit('content matches', async function () {
|
||||
const oldHead = pad.head;
|
||||
const wantAText = await pad.getInternalRevisionAText(pad.head - 1);
|
||||
assert(wantAText.text.endsWith('\nfoo\n'));
|
||||
await restoreRevision('1.2.11', padId, pad.head - 1);
|
||||
assert.equal(pad.head, oldHead + 1);
|
||||
assert.deepEqual(await pad.getInternalRevisionAText(pad.head), wantAText);
|
||||
});
|
||||
|
||||
it('authorId ignored', async function () {
|
||||
const oldHead = pad.head;
|
||||
await restoreRevision('1.2.11', padId, pad.head - 1, authorId);
|
||||
assert.equal(pad.head, oldHead + 1);
|
||||
assert.equal(await pad.getRevisionAuthor(pad.head), '');
|
||||
});
|
||||
});
|
||||
|
||||
describe('v1.3.0', function () {
|
||||
it('change is attributed to given authorId', async function () {
|
||||
const oldHead = pad.head;
|
||||
await restoreRevision('1.3.0', padId, pad.head - 1, authorId);
|
||||
assert.equal(pad.head, oldHead + 1);
|
||||
assert.equal(await pad.getRevisionAuthor(pad.head), authorId);
|
||||
});
|
||||
|
||||
it('authorId can be omitted', async function () {
|
||||
const oldHead = pad.head;
|
||||
await restoreRevision('1.3.0', padId, pad.head - 1);
|
||||
assert.equal(pad.head, oldHead + 1);
|
||||
assert.equal(await pad.getRevisionAuthor(pad.head), '');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue