tests: Use `assert` to simplify import/export tests
parent
98c42d6076
commit
fe1eceb6b5
|
@ -6,6 +6,7 @@
|
||||||
* TODO: unify those two files, and merge in a single one.
|
* TODO: unify those two files, and merge in a single one.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const assert = require('assert').strict;
|
||||||
const common = require('../../common');
|
const common = require('../../common');
|
||||||
|
|
||||||
let agent;
|
let agent;
|
||||||
|
@ -241,68 +242,32 @@ describe(__filename, function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
it('createPad', async function () {
|
it('createPad', async function () {
|
||||||
await agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
|
const res = await agent.get(`${endPoint('createPad')}&padID=${testPadId}`)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/);
|
||||||
.expect((res) => {
|
assert.equal(res.body.code, 0);
|
||||||
if (res.body.code !== 0) throw new Error('Unable to create new Pad');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('setHTML', async function () {
|
it('setHTML', async function () {
|
||||||
await agent.get(`${endPoint('setHTML')}&padID=${testPadId}` +
|
const res = await agent.get(`${endPoint('setHTML')}&padID=${testPadId}` +
|
||||||
`&html=${encodeURIComponent(test.input)}`)
|
`&html=${encodeURIComponent(test.input)}`)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/);
|
||||||
.expect((res) => {
|
assert.equal(res.body.code, 0);
|
||||||
if (res.body.code !== 0) throw new Error(`Error:${testName}`);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getHTML', async function () {
|
it('getHTML', async function () {
|
||||||
await agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
|
const res = await agent.get(`${endPoint('getHTML')}&padID=${testPadId}`)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/);
|
||||||
.expect((res) => {
|
assert.equal(res.body.data.html, test.wantHTML);
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getText', async function () {
|
it('getText', async function () {
|
||||||
await agent.get(`${endPoint('getText')}&padID=${testPadId}`)
|
const res = await agent.get(`${endPoint('getText')}&padID=${testPadId}`)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/);
|
||||||
.expect((res) => {
|
assert.equal(res.body.data.text, test.wantText);
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue