From 0765f0509065692085becffd506f65349d35175f Mon Sep 17 00:00:00 2001 From: jordanbertasso <36979824+jordanbertasso@users.noreply.github.com> Date: Tue, 12 Apr 2022 09:52:16 +1000 Subject: [PATCH] Update Discord tests --- test/backend.spec.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/test/backend.spec.js b/test/backend.spec.js index 7c02d3429..27aaf9e22 100644 --- a/test/backend.spec.js +++ b/test/backend.spec.js @@ -169,7 +169,7 @@ describe("Test reset-password", () => { }); describe("Test Discord Notification Provider", () => { - const sendNotification = async (type) => { + const sendNotification = async (hostname, port, type) => { const discordProvider = new Discord(); axios.post.mockResolvedValue({}); @@ -182,7 +182,8 @@ describe("Test Discord Notification Provider", () => { "test message", { type, - hostname: "discord.com" + (type === "port" ? ":1337" : ""), + hostname, + port, }, { status: DOWN, @@ -190,19 +191,41 @@ describe("Test Discord Notification Provider", () => { ); }; - it("should send hostname for ping monitors", async () => { - await sendNotification("ping"); + it("should send hostname for dns monitors", async () => { + const hostname = "discord.com"; + await sendNotification(hostname, null, "dns"); expect(axios.post.mock.lastCall[1].embeds[0].fields[1].value).toBe( - "discord.com" + hostname + ); + }); + + it("should send hostname for ping monitors", async () => { + const hostname = "discord.com"; + await sendNotification(hostname, null, "ping"); + + expect(axios.post.mock.lastCall[1].embeds[0].fields[1].value).toBe( + hostname ); }); it("should send hostname for port monitors", async () => { - await sendNotification("port"); + const hostname = "discord.com"; + const port = 1337; + await sendNotification(hostname, port, "port"); expect(axios.post.mock.lastCall[1].embeds[0].fields[1].value).toBe( - "discord.com:1337" + `${hostname}:${port}` + ); + }); + + it("should send hostname for steam monitors", async () => { + const hostname = "discord.com"; + const port = 1337; + await sendNotification(hostname, port, "steam"); + + expect(axios.post.mock.lastCall[1].embeds[0].fields[1].value).toBe( + `${hostname}:${port}` ); }); });