mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
tests: Add tests for exportEtherpadAdditionalContent
hook
This commit is contained in:
parent
78b44daaa8
commit
4b2e2dd9f2
2 changed files with 91 additions and 0 deletions
53
src/tests/backend/specs/ExportEtherpad.js
Normal file
53
src/tests/backend/specs/ExportEtherpad.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert').strict;
|
||||||
|
const common = require('../common');
|
||||||
|
const exportEtherpad = require('../../../node/utils/ExportEtherpad');
|
||||||
|
const padManager = require('../../../node/db/PadManager');
|
||||||
|
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||||
|
const readOnlyManager = require('../../../node/db/ReadOnlyManager');
|
||||||
|
|
||||||
|
describe(__filename, function () {
|
||||||
|
let padId;
|
||||||
|
|
||||||
|
beforeEach(async function () {
|
||||||
|
padId = common.randomString();
|
||||||
|
assert(!await padManager.doesPadExist(padId));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('exportEtherpadAdditionalContent', function () {
|
||||||
|
let hookBackup;
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
hookBackup = plugins.hooks.exportEtherpadAdditionalContent || [];
|
||||||
|
plugins.hooks.exportEtherpadAdditionalContent = [{hook_fn: () => ['custom']}];
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
plugins.hooks.exportEtherpadAdditionalContent = hookBackup;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('exports custom records', async function () {
|
||||||
|
const pad = await padManager.getPad(padId);
|
||||||
|
await pad.db.set(`custom:${padId}`, 'a');
|
||||||
|
const data = await exportEtherpad.getPadRaw(pad.id, null);
|
||||||
|
assert.equal(data[`custom:${padId}`], 'a');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('export from read-only pad uses read-only ID', async function () {
|
||||||
|
const pad = await padManager.getPad(padId);
|
||||||
|
const readOnlyId = await readOnlyManager.getReadOnlyId(padId);
|
||||||
|
await pad.db.set(`custom:${padId}`, 'a');
|
||||||
|
const data = await exportEtherpad.getPadRaw(padId, readOnlyId);
|
||||||
|
assert.equal(data[`custom:${readOnlyId}`], 'a');
|
||||||
|
assert(!(`custom:${padId}` in data));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not export records from pad with similar ID', async function () {
|
||||||
|
const pad = await padManager.getPad(padId);
|
||||||
|
await pad.db.set(`custom:${padId}x`, 'a');
|
||||||
|
const data = await exportEtherpad.getPadRaw(pad.id, null);
|
||||||
|
assert(!(`custom:${padId}x` in data));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -5,6 +5,7 @@ const authorManager = require('../../../node/db/AuthorManager');
|
||||||
const db = require('../../../node/db/DB');
|
const db = require('../../../node/db/DB');
|
||||||
const importEtherpad = require('../../../node/utils/ImportEtherpad');
|
const importEtherpad = require('../../../node/utils/ImportEtherpad');
|
||||||
const padManager = require('../../../node/db/PadManager');
|
const padManager = require('../../../node/db/PadManager');
|
||||||
|
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||||
const {randomString} = require('../../../static/js/pad_utils');
|
const {randomString} = require('../../../static/js/pad_utils');
|
||||||
|
|
||||||
describe(__filename, function () {
|
describe(__filename, function () {
|
||||||
|
@ -167,4 +168,41 @@ describe(__filename, function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('exportEtherpadAdditionalContent', function () {
|
||||||
|
let hookBackup;
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
hookBackup = plugins.hooks.exportEtherpadAdditionalContent || [];
|
||||||
|
plugins.hooks.exportEtherpadAdditionalContent = [{hook_fn: () => ['custom']}];
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
plugins.hooks.exportEtherpadAdditionalContent = hookBackup;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('imports from custom prefix', async function () {
|
||||||
|
await importEtherpad.setPadRaw(padId, JSON.stringify({
|
||||||
|
...makeExport(makeAuthorId()),
|
||||||
|
'custom:testing': 'a',
|
||||||
|
'custom:testing:foo': 'b',
|
||||||
|
}));
|
||||||
|
const pad = await padManager.getPad(padId);
|
||||||
|
assert.equal(await pad.db.get(`custom:${padId}`), 'a');
|
||||||
|
assert.equal(await pad.db.get(`custom:${padId}:foo`), 'b');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects records for pad with similar ID', async function () {
|
||||||
|
await assert.rejects(importEtherpad.setPadRaw(padId, JSON.stringify({
|
||||||
|
...makeExport(makeAuthorId()),
|
||||||
|
'custom:testingx': 'x',
|
||||||
|
})), /unexpected pad ID/);
|
||||||
|
assert(await db.get(`custom:${padId}x`) == null);
|
||||||
|
await assert.rejects(importEtherpad.setPadRaw(padId, JSON.stringify({
|
||||||
|
...makeExport(makeAuthorId()),
|
||||||
|
'custom:testingx:foo': 'x',
|
||||||
|
})), /unexpected pad ID/);
|
||||||
|
assert(await db.get(`custom:${padId}x:foo`) == null);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue