tests: Use `assert` to simplify import/export tests

pull/4960/head
Richard Hansen 2021-03-17 15:38:10 -04:00 committed by John McLear
parent 98c42d6076
commit fe1eceb6b5
1 changed files with 13 additions and 48 deletions

View File

@ -6,6 +6,7 @@
* TODO: unify those two files, and merge in a single one.
*/
const assert = require('assert').strict;
const common = require('../../common');
let agent;
@ -241,68 +242,32 @@ describe(__filename, function () {
}
it('createPad', async function () {
await agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
const res = await agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
});
.expect('Content-Type', /json/);
assert.equal(res.body.code, 0);
});
it('setHTML', async function () {
await agent.get(`${endPoint('setHTML')}&padID=${testPadId}` +
const res = await agent.get(`${endPoint('setHTML')}&padID=${testPadId}` +
`&html=${encodeURIComponent(test.input)}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
if (res.body.code !== 0) throw new Error(`Error:${testName}`);
});
.expect('Content-Type', /json/);
assert.equal(res.body.code, 0);
});
it('getHTML', async function () {
await agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
const res = await agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
const gotHtml = res.body.data.html;
if (gotHtml !== test.wantHTML) {
throw new Error(`HTML received from export is not the one we were expecting.
Test Name:
${testName}
Got:
${JSON.stringify(gotHtml)}
Want:
${JSON.stringify(test.wantHTML)}
Which is a different version of the originally imported one:
${test.input}`);
}
});
.expect('Content-Type', /json/);
assert.equal(res.body.data.html, test.wantHTML);
});
it('getText', async function () {
await agent.get(`${endPoint('getText')}&padID=${testPadId}`)
const res = await agent.get(`${endPoint('getText')}&padID=${testPadId}`)
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
const gotText = res.body.data.text;
if (gotText !== test.wantText) {
throw new Error(`Text received from export is not the one we were expecting.
Test Name:
${testName}
Got:
${JSON.stringify(gotText)}
Want:
${JSON.stringify(test.wantText)}
Which is a different version of the originally imported one:
${test.input}`);
}
});
.expect('Content-Type', /json/);
assert.equal(res.body.data.text, test.wantText);
});
});
});