Skip to content

Commit

Permalink
[tests] Adicionando testes de caminho de falha
Browse files Browse the repository at this point in the history
  • Loading branch information
AlGouvea committed Sep 6, 2024
1 parent 3eacaf2 commit 90a34cf
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/__tests__/benefitsFormController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ describe("BenefitsForm Controller Tests", () => {
expect(res.status).toBe(201);
});

it("should not create an invalid benefit", async () => {
const invalid = {
nome: "",
razaoSocial: "",
statusConvenio: "",
considerarIr: "",
descontoAut: "",
};

const res = await request(app).post("/benefits/create").send(invalid);

expect(res.status).toBe(400);
});

it("should get benefit by id", async () => {
const { body: createdBenefit } = await request(app)
.post("/benefits/create")
Expand All @@ -72,6 +86,12 @@ describe("BenefitsForm Controller Tests", () => {
expect(res.status).toBe(200);
});

it("should not get benefit without id", async () => {
const res = await request(app).get(`/benefits/A1`);

expect(res.status).toBe(400);
});

it("should get benefits", async () => {
const benefitsModelCount = await BenefitsModel.countDocuments({});
const res = await request(app).get("/benefits");
Expand All @@ -96,6 +116,12 @@ describe("BenefitsForm Controller Tests", () => {
expect(res.status).toBe(200);
});

it("should not delete benefit without id", async () => {
const res = await request(app).delete(`/benefits/delete/A1`);

expect(res.status).toBe(400);
});

it("should update benefit", async () => {
const { body: createdBenefit } = await request(app)
.post("/benefits/create")
Expand All @@ -110,4 +136,10 @@ describe("BenefitsForm Controller Tests", () => {

expect(res.status).toBe(200);
});

it("should fail to update benefit", async () => {
const res = await request(app).patch(`/benefits/update/A1`);

expect(res.status).toBe(400);
});
});

0 comments on commit 90a34cf

Please sign in to comment.