mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-13 16:12:35 +02:00
signal tests
This commit is contained in:
parent
8b0116b9f2
commit
fb67dc71cd
2 changed files with 167 additions and 11 deletions
|
@ -6,7 +6,6 @@ class Signal extends NotificationProvider {
|
||||||
name = "signal";
|
name = "signal";
|
||||||
|
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
let okMsg = "Sent Successfully.";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let data = {
|
let data = {
|
||||||
|
@ -16,10 +15,10 @@ class Signal extends NotificationProvider {
|
||||||
};
|
};
|
||||||
let config = {};
|
let config = {};
|
||||||
|
|
||||||
await axios.post(notification.signalURL, data, config)
|
await axios.post(notification.signalURL, data, config);
|
||||||
return okMsg;
|
return this.sendSuccess;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error)
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
// jest.mock("nodemailer", () => ({
|
jest.mock("axios", () => ({
|
||||||
// createTransport: jest.fn(),
|
post: jest.fn(),
|
||||||
// }));
|
}));
|
||||||
|
|
||||||
// const mockNodeMailer = require("nodemailer");
|
const axios = require("axios");
|
||||||
|
const { UP, DOWN } = require("../../src/util");
|
||||||
const Signal = require("./signal");
|
const NotificationSend = require("../notification");
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// mockNodeMailer.createTransport.mockReset();
|
axios.post.mockReset();
|
||||||
});
|
});
|
||||||
|
const Signal = require("./signal");
|
||||||
|
|
||||||
describe("notification default information", () => {
|
describe("notification default information", () => {
|
||||||
it("should have the correct name", () => {
|
it("should have the correct name", () => {
|
||||||
|
@ -16,3 +17,159 @@ describe("notification default information", () => {
|
||||||
expect(notification.name).toBe("signal");
|
expect(notification.name).toBe("signal");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("notification to act properly on send", () => {
|
||||||
|
it("should call axios with the proper default data", async () => {
|
||||||
|
|
||||||
|
let response = {
|
||||||
|
data: {
|
||||||
|
Message: "OK"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.post.mockResolvedValueOnce(response);
|
||||||
|
|
||||||
|
let notif = new Signal();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "signal",
|
||||||
|
signalNumber: "appriseURL",
|
||||||
|
signalRecipients: "asd asd, age, ge, wrh werh ,werh ,er h,as",
|
||||||
|
signalURL: "https://example.com/webhook",
|
||||||
|
};
|
||||||
|
let monitorConf = {
|
||||||
|
};
|
||||||
|
let heartbeatConf = {
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
let res = await notif.send(notificationConf, msg, monitorConf, heartbeatConf);
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://example.com/webhook", {
|
||||||
|
"message": "PassedInMessage😀",
|
||||||
|
"number": "appriseURL",
|
||||||
|
"recipients": [
|
||||||
|
"asdasd",
|
||||||
|
"age",
|
||||||
|
"ge",
|
||||||
|
"wrhwerh",
|
||||||
|
"werh",
|
||||||
|
"erh",
|
||||||
|
"as",
|
||||||
|
],
|
||||||
|
}, {});
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call axios with the proper data when monitor nil", async () => {
|
||||||
|
let response = {
|
||||||
|
data: {
|
||||||
|
Message: "OK"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.post.mockResolvedValueOnce(response);
|
||||||
|
|
||||||
|
let notif = new Signal();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "signal",
|
||||||
|
signalNumber: "appriseURL",
|
||||||
|
signalRecipients: "asd asd, age, ge, wrh werh ,werh ,er h,as",
|
||||||
|
signalURL: "https://example.com/webhook",
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
|
||||||
|
let res = await notif.send(notificationConf, msg, null, null);
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://example.com/webhook", {
|
||||||
|
"message": "PassedInMessage😀",
|
||||||
|
"number": "appriseURL",
|
||||||
|
"recipients": [
|
||||||
|
"asdasd",
|
||||||
|
"age",
|
||||||
|
"ge",
|
||||||
|
"wrhwerh",
|
||||||
|
"werh",
|
||||||
|
"erh",
|
||||||
|
"as",
|
||||||
|
],
|
||||||
|
}, {});
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("notification to act properly on error", () => {
|
||||||
|
it("should respond with an axios error on error", async () => {
|
||||||
|
|
||||||
|
axios.post.mockImplementation(() => {
|
||||||
|
throw new Error("Test Error");
|
||||||
|
});
|
||||||
|
let notif = new Signal();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "signal",
|
||||||
|
signalNumber: "appriseURL",
|
||||||
|
signalRecipients: "asd asd, age, ge, wrh werh ,werh ,er h,as",
|
||||||
|
signalURL: "https://example.com/webhook",
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
|
||||||
|
try {
|
||||||
|
await notif.send(notificationConf, msg, null, null);
|
||||||
|
expect("Error thrown").toBe(false);
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.message).toBe("Error: Error: Test Error ");
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://example.com/webhook", {
|
||||||
|
"message": "PassedInMessage😀",
|
||||||
|
"number": "appriseURL",
|
||||||
|
"recipients": [
|
||||||
|
"asdasd",
|
||||||
|
"age",
|
||||||
|
"ge",
|
||||||
|
"wrhwerh",
|
||||||
|
"werh",
|
||||||
|
"erh",
|
||||||
|
"as",
|
||||||
|
],
|
||||||
|
}, {});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("notification to get proper data from Notification.send", () => {
|
||||||
|
it("should call axios with proper data", async () => {
|
||||||
|
let response = {
|
||||||
|
data: {
|
||||||
|
Message: "OK"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.post.mockResolvedValueOnce(response);
|
||||||
|
let notificationConf = {
|
||||||
|
type: "signal",
|
||||||
|
signalNumber: "appriseURL",
|
||||||
|
signalRecipients: "asd asd, age, ge, wrh werh ,werh ,er h,as",
|
||||||
|
signalURL: "https://example.com/webhook",
|
||||||
|
};
|
||||||
|
let monitorConf = {
|
||||||
|
};
|
||||||
|
let heartbeatConf = {
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
|
||||||
|
NotificationSend.Notification.init();
|
||||||
|
let res = await NotificationSend.Notification.send(notificationConf, msg, monitorConf, heartbeatConf);
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://example.com/webhook", {
|
||||||
|
"message": "PassedInMessage😀",
|
||||||
|
"number": "appriseURL",
|
||||||
|
"recipients": [
|
||||||
|
"asdasd",
|
||||||
|
"age",
|
||||||
|
"ge",
|
||||||
|
"wrhwerh",
|
||||||
|
"werh",
|
||||||
|
"erh",
|
||||||
|
"as",
|
||||||
|
],
|
||||||
|
}, {});
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue