From 994b9f4bdf7646a25b454c461caeab6057393ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nat=C3=A1lia=20Rodrigues?= Date: Fri, 20 Sep 2024 21:32:34 -0300 Subject: [PATCH] test: send error if answer not 200 Co-authored-by: Gabriel Monteiro Co-authored-by: Jessica Luiza Silva de Oliveira Co-authored-by: Marcella Sanderle --- src/app/__tests__/forum.service.spec.tsx | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/app/__tests__/forum.service.spec.tsx b/src/app/__tests__/forum.service.spec.tsx index 38e28d2..c717a7b 100644 --- a/src/app/__tests__/forum.service.spec.tsx +++ b/src/app/__tests__/forum.service.spec.tsx @@ -58,6 +58,32 @@ describe("getAllPublicacao", () => { } } }); + + it("deve lançar um erro se o status da resposta não for 200", async () => { + global.fetch = jest.fn().mockResolvedValue({ + json: async () => ({ + data: null, + message: "Erro na API", + status: 400, + }), + status: 400, + }); + + const offset = 0; + const filter = { titulo: "Exemplo" }; + const order: IOrder = { + column: "descricao", + dir: "DESC", + }; + + try { + await getAllPublicacao(offset, filter, order); + } catch (error) { + if (error instanceof Error) { + expect(error.message).toBe("Erro na API"); + } + } + }); }); describe("postPublicacao", () => { @@ -284,3 +310,5 @@ describe("deletePublicacaoById", () => { } }); }); + +// npx jest forum.service.spec.tsx \ No newline at end of file