Skip to content

Commit

Permalink
test: error if answer is not 201
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 95490bc commit 8fa1821
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 @@ -122,6 +122,34 @@ describe("postPublicacao", () => {
}
}
});

it("deve lançar um erro quando a resposta não for 201", async () => {
// Mock para simular uma resposta de erro
global.fetch = jest.fn().mockResolvedValue({
json: async () => ({
data: null,
message: "Erro ao criar publicação",
}),
status: 400, // status diferente de 201
});

const body = {
idUsuario: 1,
titulo: "Título de Exemplo",
descricao: "Descrição de Exemplo",
dataHora: "2023-11-06T12:00:00",
categoria: ECategoriaPublicacao.GERAL,
contagemReportes: 0,
};

try {
await postPublicacao(body, token);
} catch (error) {
if (error instanceof Error) {
expect(error.message).toBe("Erro ao criar publicação");
}
}
});
});

describe("updatePublicacao", () => {
Expand Down

0 comments on commit 8fa1821

Please sign in to comment.