tests: Restructure read-only pad export tests
This also adds coverage for `.etherpad` exports.pull/5096/head
parent
dbd76f0c5d
commit
0f5a4bd1f8
|
@ -106,23 +106,52 @@ describe(__filename, function () {
|
|||
.expect((res) => assert.equal(res.body.data.text, padText.toString()));
|
||||
});
|
||||
|
||||
for (const authn of [false, true]) {
|
||||
it(`can export from read-only pad ID, authn ${authn}`, async function () {
|
||||
settings.requireAuthentication = authn;
|
||||
const get = (ep) => {
|
||||
let req = agent.get(ep);
|
||||
if (authn) req = req.auth('user', 'user-password');
|
||||
return req.expect(200);
|
||||
};
|
||||
const ro = await get(`${endPoint('getReadOnlyID')}&padID=${testPadId}`)
|
||||
.expect((res) => assert.ok(JSON.parse(res.text).data.readOnlyID));
|
||||
const readOnlyId = JSON.parse(ro.text).data.readOnlyID;
|
||||
await get(`/p/${readOnlyId}/export/html`)
|
||||
.expect((res) => assert(res.text.indexOf('This is the') !== -1));
|
||||
await get(`/p/${readOnlyId}/export/txt`)
|
||||
.expect((res) => assert(res.text.indexOf('This is the') !== -1));
|
||||
describe('export from read-only pad ID', function () {
|
||||
let readOnlyId;
|
||||
|
||||
// This ought to be before(), but it must run after the top-level beforeEach() above.
|
||||
beforeEach(async function () {
|
||||
if (readOnlyId != null) return;
|
||||
await agent.post(`/p/${testPadId}/import`)
|
||||
.attach('file', padText, {filename: '/test.txt', contentType: 'text/plain'})
|
||||
.expect(200);
|
||||
const res = await agent.get(`${endPoint('getReadOnlyID')}&padID=${testPadId}`)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => assert.equal(res.body.code, 0));
|
||||
readOnlyId = res.body.data.readOnlyID;
|
||||
});
|
||||
}
|
||||
|
||||
for (const authn of [false, true]) {
|
||||
describe(`requireAuthentication = ${authn}`, function () {
|
||||
// This ought to be before(), but it must run after the top-level beforeEach() above.
|
||||
beforeEach(async function () {
|
||||
settings.requireAuthentication = authn;
|
||||
});
|
||||
|
||||
for (const exportType of ['html', 'txt', 'etherpad']) {
|
||||
describe(`export to ${exportType}`, function () {
|
||||
let text;
|
||||
|
||||
// This ought to be before(), but it must run after the top-level beforeEach() above.
|
||||
beforeEach(async function () {
|
||||
if (text != null) return;
|
||||
let req = agent.get(`/p/${readOnlyId}/export/${exportType}`);
|
||||
if (authn) req = req.auth('user', 'user-password');
|
||||
const res = await req
|
||||
.expect(200)
|
||||
.buffer(true).parse(superagent.parse.text);
|
||||
text = res.text;
|
||||
});
|
||||
|
||||
it('export OK', async function () {
|
||||
assert.match(text, /This is the/);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('Import/Export tests requiring AbiWord/LibreOffice', function () {
|
||||
before(async function () {
|
||||
|
|
Loading…
Reference in New Issue