diff --git a/src/tests/backend/specs/api/importexport.js b/src/tests/backend/specs/api/importexport.js index 1626d3e6e..ceced447f 100644 --- a/src/tests/backend/specs/api/importexport.js +++ b/src/tests/backend/specs/api/importexport.js @@ -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); }); }); });