Skip to content

Commit

Permalink
test: use response.json() over parsing response.body
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Mar 13, 2024
1 parent 9857259 commit 19979b3
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/plugins/doc-to-txt/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe("DOC-to-TXT conversion plugin", () => {
headers,
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Bad Request",
statusCode: 400,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/docx-to-html/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("DOCX-to-HTML conversion plugin", () => {
headers,
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Bad Request",
statusCode: 400,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/embed-html-images/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("Embed-HTML-Images plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
code: "ENOENT",
errno: expect.any(Number),
path: expect.any(String),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/html-to-txt/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("HTML-to-TXT conversion plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Bad Request",
statusCode: 400,
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/pdf-to-html/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe("PDF-to-HTML conversion plugin", () => {
},
});

const { body, docLocation } = JSON.parse(response.body);
const { body, docLocation } = response.json();
const dom = new JSDOM(body);

expect(body).not.toMatch(artifacts);
Expand Down Expand Up @@ -141,7 +141,7 @@ describe("PDF-to-HTML conversion plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Bad Request",
statusCode: 400,
Expand Down Expand Up @@ -169,7 +169,7 @@ describe("PDF-to-HTML conversion plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Internal Server Error",
message: "test error",
statusCode: 500,
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/pdf-to-txt/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("PDF-to-TXT conversion plugin", () => {
},
});

const { body } = JSON.parse(response.body);
const { body } = response.json();

expect(body).toMatch("The NHS belongs to the people");
expect(isHtml(body)).toBe(false);
Expand Down Expand Up @@ -114,7 +114,7 @@ describe("PDF-to-TXT conversion plugin", () => {
},
});

const { body, docLocation } = JSON.parse(response.body);
const { body, docLocation } = response.json();

expect(body).toMatch("The NHS belongs to the people");
// String found at end of second page
Expand Down Expand Up @@ -149,7 +149,7 @@ describe("PDF-to-TXT conversion plugin", () => {
},
});

const { body } = JSON.parse(response.body);
const { body } = response.json();
const dom = new JSDOM(body);

expect(isHtml(body)).toBe(true);
Expand Down Expand Up @@ -205,7 +205,7 @@ describe("PDF-to-TXT conversion plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Bad Request",
statusCode: 400,
Expand Down Expand Up @@ -249,7 +249,7 @@ describe("PDF-to-TXT conversion plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Internal Server Error",
message: "test error",
statusCode: 500,
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/rtf-to-html/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("RTF-to-HTML conversion plugin", () => {
},
});

const { body, docLocation } = JSON.parse(response.body);
const { body, docLocation } = response.json();
const dom = new JSDOM(body);

expect(body).not.toMatch(artifacts);
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("RTF-to-HTML conversion plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Bad Request",
statusCode: 400,
Expand All @@ -151,7 +151,7 @@ describe("RTF-to-HTML conversion plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Internal Server Error",
message: "test error",
statusCode: 500,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tidy-html/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("Tidy-HTML plugin", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
statusCode: 400,
error: "Bad Request",
message: "querystring.language not a valid IANA language tag",
Expand Down
2 changes: 1 addition & 1 deletion src/routes/admin/healthcheck/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("Healthcheck route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
8 changes: 4 additions & 4 deletions src/routes/doc/txt/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("DOC-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Body cannot be empty",
statusCode: 400,
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("DOC-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type",
statusCode: 415,
Expand All @@ -122,7 +122,7 @@ describe("DOC-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type: application/html",
statusCode: 415,
Expand All @@ -141,7 +141,7 @@ describe("DOC-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/docs/openapi/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("OpenAPI route", () => {
},
});

expect(JSON.parse(response.body)).toHaveProperty("openapi");
expect(response.json()).toHaveProperty("openapi");
expect(response.headers).toMatchObject({
"cache-control": "public, max-age=1800",
});
Expand All @@ -54,7 +54,7 @@ describe("OpenAPI route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/docs/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("Docs route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
8 changes: 4 additions & 4 deletions src/routes/docx/html/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("DOCX-to-HTML route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Body cannot be empty",
statusCode: 400,
Expand Down Expand Up @@ -157,7 +157,7 @@ describe("DOCX-to-HTML route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type",
statusCode: 415,
Expand All @@ -179,7 +179,7 @@ describe("DOCX-to-HTML route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type: application/html",
statusCode: 415,
Expand All @@ -199,7 +199,7 @@ describe("DOCX-to-HTML route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
8 changes: 4 additions & 4 deletions src/routes/docx/txt/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("DOCX-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Body cannot be empty",
statusCode: 400,
Expand Down Expand Up @@ -145,7 +145,7 @@ describe("DOCX-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type",
statusCode: 415,
Expand All @@ -167,7 +167,7 @@ describe("DOCX-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type: application/html",
statusCode: 415,
Expand All @@ -187,7 +187,7 @@ describe("DOCX-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
8 changes: 4 additions & 4 deletions src/routes/html/txt/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("HTML-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Body cannot be empty",
statusCode: 400,
Expand Down Expand Up @@ -113,7 +113,7 @@ describe("HTML-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type",
statusCode: 415,
Expand All @@ -134,7 +134,7 @@ describe("HTML-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type: application/html",
statusCode: 415,
Expand All @@ -153,7 +153,7 @@ describe("HTML-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
8 changes: 4 additions & 4 deletions src/routes/pdf/html/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("PDF-to-HTML route", () => {
},
})
.then((response) => {
expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Body cannot be empty",
statusCode: 400,
Expand Down Expand Up @@ -121,7 +121,7 @@ describe("PDF-to-HTML route", () => {
},
})
.then((response) => {
expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type",
statusCode: 415,
Expand Down Expand Up @@ -152,7 +152,7 @@ describe("PDF-to-HTML route", () => {
},
})
.then((response) => {
expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type: application/html",
statusCode: 415,
Expand Down Expand Up @@ -181,7 +181,7 @@ describe("PDF-to-HTML route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
8 changes: 4 additions & 4 deletions src/routes/pdf/txt/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("PDF-to-TXT route", () => {
},
})
.then((response) => {
expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Bad Request",
message: "Body cannot be empty",
statusCode: 400,
Expand Down Expand Up @@ -172,7 +172,7 @@ describe("PDF-to-TXT route", () => {
},
})
.then((response) => {
expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type",
statusCode: 415,
Expand Down Expand Up @@ -203,7 +203,7 @@ describe("PDF-to-TXT route", () => {
},
})
.then((response) => {
expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Unsupported Media Type",
message: "Unsupported Media Type: application/html",
statusCode: 415,
Expand Down Expand Up @@ -232,7 +232,7 @@ describe("PDF-to-TXT route", () => {
},
});

expect(JSON.parse(response.body)).toStrictEqual({
expect(response.json()).toStrictEqual({
error: "Not Acceptable",
message: "Not Acceptable",
statusCode: 406,
Expand Down
Loading

0 comments on commit 19979b3

Please sign in to comment.