Skip to content

Commit

Permalink
more tests: add checks on "link" and "query-total" headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Digitalone1 committed Dec 23, 2022
1 parent e8d3d63 commit f1d45fe
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/tests_integration/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ describe("Get /api/packages", () => {
expect(p.pointer == null).toBeTruthy();
}
});
test("Should respond with the expected headers", async () => {
const res = await request(app).get("/api/packages");
expect(res.headers["link"].length).toBeGreaterThan(0);
expect(res.headers["query-total"].match(/^\d+$/) === null).toBeFalsy();
});
test("Should 404 on invalid Method", async () => {
const res = await request(app).patch("/api/packages");
expect(res).toHaveHTTPCode(404);
Expand Down Expand Up @@ -300,6 +305,11 @@ describe("GET /api/packages/search", () => {
expect(p.pointer == null).toBeTruthy();
}
});
test("Valid Search Returns Expected Headers", async () => {
const res = await request(app).get("/api/packages/search?q=language");
expect(res.headers["link"].length).toBeGreaterThan(0);
expect(res.headers["query-total"].match(/^\d+$/) === null).toBeFalsy();
});
test("Invalid Search Returns Array", async () => {
const res = await request(app).get("/api/packages/search?q=not-one-match");
expect(res.body).toBeArray();
Expand Down Expand Up @@ -860,6 +870,11 @@ describe("GET /api/themes", () => {
expect(p.pointer == null).toBeTruthy();
}
});
test("Should respond with the expected headers", async () => {
const res = await request(app).get("/api/themes");
expect(res.headers["link"].length).toBeGreaterThan(0);
expect(res.headers["query-total"].match(/^\d+$/) === null).toBeFalsy();
});
test("Should 404 on invalid Method", async () => {
const res = await request(app).patch("/api/themes");
expect(res).toHaveHTTPCode(404);
Expand All @@ -882,7 +897,7 @@ describe("GET /api/themes/search", () => {
expect(p.pointer == null).toBeTruthy();
}
});
test("Valid Search Returns Valid Ddata", async () => {
test("Valid Search Returns Valid Data", async () => {
const res = await request(app).get("/api/themes/search?q=syntax");
for (const p of res.body) {
expect(typeof p.name === "string").toBeTruthy();
Expand All @@ -891,6 +906,11 @@ describe("GET /api/themes/search", () => {
expect(typeof p.releases.latest === "string").toBeTruthy();
}
});
test("Valid Search Returns Expected Headers", async () => {
const res = await request(app).get("/api/themes/search?q=syntax");
expect(res.headers["link"].length).toBeGreaterThan(0);
expect(res.headers["query-total"].match(/^\d+$/) === null).toBeFalsy();
});
test("Invalid Search Returns Array", async () => {
const res = await request(app).get("/api/themes/search?q=not-one-match");
expect(res.body).toBeArray();
Expand Down

0 comments on commit f1d45fe

Please sign in to comment.