Merge pull request #1728 from tamasmagyar/test/simplify-discord-unit-tests

test: simplified discord unit tests
This commit is contained in:
Louis Lam 2022-06-13 21:02:12 +08:00 committed by GitHub
commit fa60672cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -159,7 +159,6 @@ describe("Test genSecret", () => {
expect(secret).toContain("A");
expect(secret).toContain("9");
});
});
describe("Test reset-password", () => {
@ -169,6 +168,9 @@ describe("Test reset-password", () => {
});
describe("Test Discord Notification Provider", () => {
const hostname = "discord.com";
const port = 1337;
const sendNotification = async (hostname, port, type) => {
const discordProvider = new Discord();
@ -191,42 +193,14 @@ describe("Test Discord Notification Provider", () => {
);
};
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(
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
);
expect(axios.post.mock.lastCall[1].embeds[0].fields[1].value).toBe(hostname);
});
it("should send hostname for port monitors", async () => {
const hostname = "discord.com";
const port = 1337;
await sendNotification(hostname, port, "port");
expect(axios.post.mock.lastCall[1].embeds[0].fields[1].value).toBe(
`${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}`
);
it.each([ "dns", "port", "steam" ])("should send hostname for %p monitors", async (type) => {
await sendNotification(hostname, port, type);
expect(axios.post.mock.lastCall[1].embeds[0].fields[1].value).toBe(`${hostname}:${port}`);
});
});