Browse Source

pushover tests

deefdragon/notif-tests
Jeffrey Koehler 3 years ago
parent
commit
a6f14f57cf
  1. 8
      server/notification-providers/matrix.spec.js
  2. 278
      server/notification-providers/pushover.spec.js

8
server/notification-providers/matrix.spec.js

@ -33,7 +33,7 @@ describe("notification to act properly on send", () => {
} }
}; };
axios.put.mockResolvedValueOnce(response); axios.put.mockResolvedValueOnce(response);
Crypto.randomBytes.mockReturnValueOnce(new Buffer("abcd")); Crypto.randomBytes.mockReturnValueOnce(Buffer.from("abcd"));
let notif = new Matrix(); let notif = new Matrix();
@ -68,7 +68,7 @@ describe("notification to act properly on send", () => {
} }
}; };
axios.put.mockResolvedValueOnce(response); axios.put.mockResolvedValueOnce(response);
Crypto.randomBytes.mockReturnValueOnce(new Buffer("abcd")); Crypto.randomBytes.mockReturnValueOnce(Buffer.from("abcd"));
let notif = new Matrix(); let notif = new Matrix();
let notificationConf = { let notificationConf = {
@ -100,7 +100,7 @@ describe("notification to act properly on error", () => {
axios.put.mockImplementation(() => { axios.put.mockImplementation(() => {
throw new Error("Test Error"); throw new Error("Test Error");
}); });
Crypto.randomBytes.mockReturnValueOnce(new Buffer("abcd")); Crypto.randomBytes.mockReturnValueOnce(Buffer.from("abcd"));
let notif = new Matrix(); let notif = new Matrix();
let notificationConf = { let notificationConf = {
@ -142,7 +142,7 @@ describe("notification to get proper data from Notification.send", () => {
} }
}; };
axios.put.mockResolvedValueOnce(response); axios.put.mockResolvedValueOnce(response);
Crypto.randomBytes.mockReturnValueOnce(new Buffer("abcd")); Crypto.randomBytes.mockReturnValueOnce(Buffer.from("abcd"));
let notificationConf = { let notificationConf = {
type: "matrix", type: "matrix",

278
server/notification-providers/pushover.spec.js

@ -18,124 +18,160 @@ describe("notification default information", () => {
}); });
}); });
// describe("notification to act properly on send", () => { describe("notification to act properly on send", () => {
// it("should call axios with the proper default data", async () => { it("should call axios with the proper default data", async () => {
// let response = { let response = {
// data: { data: {
// Message: "OK" Message: "OK"
// } }
// }; };
// axios.post.mockResolvedValueOnce(response); axios.post.mockResolvedValueOnce(response);
// let notif = new Pushover(); let notif = new Pushover();
// let notificationConf = { let notificationConf = {
// type: "octopush", type: "octopush",
// pushoveruserkey: "123", pushoveruserkey: "123",
// pushoverapptoken: "token", pushoverapptoken: "token",
// pushoversounds: "ding", pushoversounds: "ding",
// pushoverpriority: "6", pushoverpriority: "6",
// pushovertitle: "Important Title!", pushovertitle: "Important Title!",
// }; };
// let monitorConf = { let monitorConf = {
// }; };
// let heartbeatConf = { let heartbeatConf = {
// time: "example time", time: "example time",
// }; };
// let msg = "PassedInMessage😀"; let msg = "PassedInMessage😀";
// let res = await notif.send(notificationConf, msg, monitorConf, heartbeatConf); let res = await notif.send(notificationConf, msg, monitorConf, heartbeatConf);
// expect(axios.post).toHaveBeenCalledWith("", { expect(axios.post).toHaveBeenCalledWith("https://api.pushover.net/1/messages.json", {
// }); "expire": "3600",
// expect(res).toBe("Sent Successfully."); "html": 1,
// }); "message": "<b>Uptime Kuma Alert</b>\n\n<b>Message</b>:PassedInMessage😀\n<b>Time (UTC)</b>:example time",
"priority": "6",
// it("should call axios with the proper data when monitor nil", async () => { "retry": "30",
// let response = { "sound": "ding",
// data: { "title": "Important Title!",
// Message: "OK" "token": "token",
// } "user": "123",
// }; });
// axios.post.mockResolvedValueOnce(response); expect(res).toBe("Sent Successfully.");
});
// let notif = new Pushover();
// let notificationConf = { it("should call axios with the proper data when monitor nil", async () => {
// type: "octopush", let response = {
// pushoveruserkey: "123", data: {
// pushoverapptoken: "token", Message: "OK"
// pushoversounds: "ding", }
// pushoverpriority: "6", };
// pushovertitle: "Important Title!", axios.post.mockResolvedValueOnce(response);
// };
// let msg = "PassedInMessage😀"; let notif = new Pushover();
let notificationConf = {
// let res = await notif.send(notificationConf, msg, null, null); type: "octopush",
pushoveruserkey: "123",
// expect(axios.post).toHaveBeenCalledWith("", { pushoverapptoken: "token",
// }); pushoversounds: "ding",
// expect(res).toBe("Sent Successfully."); pushoverpriority: "6",
// }); pushovertitle: "Important Title!",
};
// }); let msg = "PassedInMessage😀";
// describe("notification to act properly on error", () => { let res = await notif.send(notificationConf, msg, null, null);
// it("should respond with an axios error on error", async () => {
expect(axios.post).toHaveBeenCalledWith("https://api.pushover.net/1/messages.json", {
// axios.post.mockImplementation(() => { "expire": "3600",
// throw new Error("Test Error"); "html": 1,
// }); "message": "<b>Uptime Kuma Pushover testing successful.</b>",
// let notif = new Pushover(); "priority": "6",
// let notificationConf = { "retry": "30",
// type: "octopush", "sound": "ding",
// pushoveruserkey: "123", "title": "Important Title!",
// pushoverapptoken: "token", "token": "token",
// pushoversounds: "ding", "user": "123",
// pushoverpriority: "6", });
// pushovertitle: "Important Title!", expect(res).toBe("Sent Successfully.");
// }; });
// let msg = "PassedInMessage😀";
});
// try {
// await notif.send(notificationConf, msg, null, null); describe("notification to act properly on error", () => {
// expect("Error thrown").toBe(false); it("should respond with an axios error on error", async () => {
// } catch (e) {
// expect(e.message).toBe("Error: Error: Test Error "); axios.post.mockImplementation(() => {
// } throw new Error("Test Error");
});
// expect(axios.post).toHaveBeenCalledWith("", { let notif = new Pushover();
// }); let notificationConf = {
// }); type: "octopush",
pushoveruserkey: "123",
// }); pushoverapptoken: "token",
pushoversounds: "ding",
// describe("notification to get proper data from Notification.send", () => { pushoverpriority: "6",
// it("should call axios with proper data", async () => { pushovertitle: "Important Title!",
// let response = { };
// data: { let msg = "PassedInMessage😀";
// Message: "OK"
// } try {
// }; await notif.send(notificationConf, msg, null, null);
// axios.post.mockResolvedValueOnce(response); expect("Error thrown").toBe(false);
// let notificationConf = { } catch (e) {
// type: "octopush", expect(e.message).toBe("Error: Error: Test Error ");
// pushoveruserkey: "123", }
// pushoverapptoken: "token",
// pushoversounds: "ding", expect(axios.post).toHaveBeenCalledWith("https://api.pushover.net/1/messages.json", {
// pushoverpriority: "6", "expire": "3600",
// pushovertitle: "Important Title!", "html": 1,
// }; "message": "<b>Uptime Kuma Pushover testing successful.</b>",
// let monitorConf = { "priority": "6",
// }; "retry": "30",
// let heartbeatConf = { "sound": "ding",
// time: "example time", "title": "Important Title!",
// }; "token": "token",
// let msg = "PassedInMessage😀"; "user": "123",
});
// NotificationSend.Notification.init(); });
// let res = await NotificationSend.Notification.send(notificationConf, msg, monitorConf, heartbeatConf);
// expect(axios.post).toHaveBeenCalledWith("", { });
// });
// expect(res).toBe("Sent Successfully."); 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: "pushover",
pushoveruserkey: "123",
pushoverapptoken: "token",
pushoversounds: "ding",
pushoverpriority: "6",
pushovertitle: "Important Title!",
};
let monitorConf = {
};
let heartbeatConf = {
time: "example time",
};
let msg = "PassedInMessage😀";
NotificationSend.Notification.init();
let res = await NotificationSend.Notification.send(notificationConf, msg, monitorConf, heartbeatConf);
expect(axios.post).toHaveBeenCalledWith("https://api.pushover.net/1/messages.json", {
"expire": "3600",
"html": 1,
"message": "<b>Uptime Kuma Alert</b>\n\n<b>Message</b>:PassedInMessage😀\n<b>Time (UTC)</b>:example time",
"priority": "6",
"retry": "30",
"sound": "ding",
"title": "Important Title!",
"token": "token",
"user": "123",
});
expect(res).toBe("Sent Successfully.");
});
});

Loading…
Cancel
Save