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