Skip to content

Commit

Permalink
test: send error if answer not 200
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Monteiro <gabrielmonteiro1203@gmail.com>
Co-authored-by: Jessica Luiza Silva de Oliveira <jluiza409@gmail.com>
Co-authored-by: Marcella Sanderle <marcellasanderle@gmail.com>
  • Loading branch information
4 people committed Sep 21, 2024
1 parent 8fa1821 commit 994b9f4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/app/__tests__/forum.service.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -284,3 +310,5 @@ describe("deletePublicacaoById", () => {
}
});
});

// npx jest forum.service.spec.tsx

0 comments on commit 994b9f4

Please sign in to comment.