From 3eacaf2ef97947fa4a78b1a75d09cac61863ac62 Mon Sep 17 00:00:00 2001 From: AlGouvea Date: Fri, 6 Sep 2024 17:33:25 -0300 Subject: [PATCH 1/2] [fix] Removendo controller depreciada --- src/Controllers/newController.js | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 src/Controllers/newController.js diff --git a/src/Controllers/newController.js b/src/Controllers/newController.js deleted file mode 100644 index 7326997..0000000 --- a/src/Controllers/newController.js +++ /dev/null @@ -1,25 +0,0 @@ -const Beneficios = require("../Models/benefitsCreateSchema"); - -const createNew = async (req, res) => { - try { - const newSchema = new Beneficios(req.body); - await newSchema.save(); // pausa até o banco salvar - return res.status(201).send(newSchema); - } catch (error) { - return res.status(400).send(error); - } -}; - -const getNews = async (req, res) => { - try { - const newSchema = await Beneficios.find(); - res.status(200).send(newSchema); - } catch (error) { - res.status(500).send(error); - } -}; - -module.exports = { - createNew, - getNews, -}; From 90a34cff586b9a200ebd4bc372fc8ffce039bcb5 Mon Sep 17 00:00:00 2001 From: AlGouvea Date: Fri, 6 Sep 2024 17:51:26 -0300 Subject: [PATCH 2/2] [tests] Adicionando testes de caminho de falha --- src/__tests__/benefitsFormController.test.js | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/__tests__/benefitsFormController.test.js b/src/__tests__/benefitsFormController.test.js index af0ff75..0a79a98 100644 --- a/src/__tests__/benefitsFormController.test.js +++ b/src/__tests__/benefitsFormController.test.js @@ -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") @@ -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"); @@ -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") @@ -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); + }); });