Skip to content

Commit ed78b56

Browse files
committed
tests: Refine copyPadWithoutHistory tests
1 parent d74dd23 commit ed78b56

File tree

1 file changed

+22
-33
lines changed
  • src/tests/backend/specs/api

1 file changed

+22
-33
lines changed

src/tests/backend/specs/api/pad.js

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,16 @@ const ulSpaceHtml = '<!doctype html><html><body><ul class="bullet"> <li>one</li>
4848
const expectedSpaceHtml = '<!doctype html><html><body><ul class="bullet"><li>one</ul></body></html>';
4949

5050
describe(__filename, function () {
51-
before(async function () { agent = await common.init(); });
51+
before(async function () {
52+
agent = await common.init();
53+
const res = await agent.get('/api/')
54+
.expect(200)
55+
.expect('Content-Type', /json/);
56+
apiVersion = res.body.currentVersion;
57+
assert(apiVersion);
58+
});
5259

5360
describe('Sanity checks', function () {
54-
it('can connect', async function () {
55-
await agent.get('/api/')
56-
.expect(200)
57-
.expect('Content-Type', /json/);
58-
});
59-
60-
it('finds the version tag', async function () {
61-
const res = await agent.get('/api/')
62-
.expect(200);
63-
apiVersion = res.body.currentVersion;
64-
assert(apiVersion);
65-
});
66-
6761
it('errors with invalid APIKey', async function () {
6862
// This is broken because Etherpad doesn't handle HTTP codes properly see #2343
6963
// If your APIKey is password you deserve to fail all tests anyway
@@ -523,37 +517,32 @@ describe(__filename, function () {
523517
assert.equal(receivedHtml, expectedHtml);
524518
});
525519

526-
describe('when try copy a pad with a group that does not exist', function () {
527-
const padId = makeid();
528-
const padWithNonExistentGroup = `notExistentGroup$${padId}`;
529-
it('throws an error', async function () {
530-
const res = await agent.get(`${endPoint('copyPadWithoutHistory')}` +
531-
`&sourceID=${sourcePadId}` +
532-
`&destinationID=${padWithNonExistentGroup}&force=true`)
533-
.expect(200);
534-
assert.equal(res.body.code, 1);
535-
});
520+
it('copying to a non-existent group throws an error', async function () {
521+
const padWithNonExistentGroup = `notExistentGroup$${newPad}`;
522+
const res = await agent.get(`${endPoint('copyPadWithoutHistory')}` +
523+
`&sourceID=${sourcePadId}` +
524+
`&destinationID=${padWithNonExistentGroup}&force=true`)
525+
.expect(200);
526+
assert.equal(res.body.code, 1);
536527
});
537528

538-
describe('when try copy a pad and destination pad already exist', function () {
539-
const padIdExistent = makeid();
540-
541-
before(async function () {
542-
await createNewPadWithHtml(padIdExistent, ulHtml);
529+
describe('copying to an existing pad', function () {
530+
beforeEach(async function () {
531+
await createNewPadWithHtml(newPad, ulHtml);
543532
});
544533

545-
it('force=false throws an error', async function () {
534+
it('force=false fails', async function () {
546535
const res = await agent.get(`${endPoint('copyPadWithoutHistory')}` +
547536
`&sourceID=${sourcePadId}` +
548-
`&destinationID=${padIdExistent}&force=false`)
537+
`&destinationID=${newPad}&force=false`)
549538
.expect(200);
550539
assert.equal(res.body.code, 1);
551540
});
552541

553-
it('force=true returns a successful response', async function () {
542+
it('force=true succeeds', async function () {
554543
const res = await agent.get(`${endPoint('copyPadWithoutHistory')}` +
555544
`&sourceID=${sourcePadId}` +
556-
`&destinationID=${padIdExistent}&force=true`)
545+
`&destinationID=${newPad}&force=true`)
557546
.expect(200);
558547
assert.equal(res.body.code, 0);
559548
});

0 commit comments

Comments
 (0)