Skip to content

Commit

Permalink
adds tests with invalid bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
agosmou committed Nov 17, 2023
1 parent 2a85e69 commit c153a88
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions server/__tests__/calculation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ describe("Calculation API Endpoints", () => {
newCalcId = res.body.id;
});

// POST "/" Create a calculation with invalid body (Admin only)
it("should create a calculation", async () => {
const res = await request(server)
.post("/api/calculations")
.set("Authorization", `Bearer ${adminToken}`)
.send({
name: true,
description: 1,
deprecated: true,
id: "string"
});
expect(res.statusCode).toEqual(400);
});

// PUT "/:id" Update calculation (Admin only)
it("should update a calculation", async () => {
const res = await request(server)
Expand All @@ -106,6 +120,20 @@ describe("Calculation API Endpoints", () => {
expect(res.statusCode).toEqual(200);
});

// PUT "/:id" Update calculation with invalid body(Admin only)
it("should update a calculation", async () => {
const res = await request(server)
.put(`/api/calculations/${newCalcId}`)
.set("Authorization", `Bearer ${adminToken}`)
.send({
name: true,
description: 1,
deprecated: true,
id: "string"
});
expect(res.statusCode).toEqual(400);
});

// PUT "/:id" Update calculation using inexistent id (Admin only)
//TODO: this endpoint logic needs error handling for inexistent ids

Expand Down

0 comments on commit c153a88

Please sign in to comment.