improve test coverage
This commit is contained in:
1 parent
d5f1032bdf
commit
1e26fb1e3b
15 files changed
+388
-71
No files matched your search
@@ -40,5 +40,29 @@ describe("DiscordService", () => {
|
||||
const alert = service.buildAlert(buildMonitor(), buildIncident());
|
||||
await expect(service.sendMessage(alert, channel)).rejects.toBeInstanceOf(ApiError);
|
||||
});
|
||||
});
|
||||
|
||||
it("returns false when webhook post fails", async () => {
|
||||
const service = new (await import("@/services/infrastructure/NotificationServices/Discord.js")).default();
|
||||
const getGot = () => jest.requireMock("got").default;
|
||||
getGot().post.mockRejectedValue(new Error("net"));
|
||||
const channel = buildChannel();
|
||||
const alert = service.buildAlert(buildMonitor(), buildIncident());
|
||||
const ok = await service.sendMessage(alert, channel);
|
||||
expect(ok).toBe(false);
|
||||
});
|
||||
|
||||
it("uses red color embed when status is down", async () => {
|
||||
const service = new DiscordService();
|
||||
const getGot = () => jest.requireMock("got").default;
|
||||
getGot().post.mockResolvedValue({});
|
||||
const channel = buildChannel();
|
||||
const alert = service.buildAlert(
|
||||
buildMonitor({ status: "down" }),
|
||||
buildIncident()
|
||||
);
|
||||
await service.sendMessage(alert, channel);
|
||||
const call = getGot().post.mock.calls[0];
|
||||
const payload = call[1].json;
|
||||
expect(payload.embeds[0].color).toBe(16711680);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user