mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-13 08:02:35 +02:00
pushbullet test
This commit is contained in:
parent
d818ce866d
commit
b229f36ea1
4 changed files with 336 additions and 32 deletions
|
@ -8,7 +8,6 @@ class Pushbullet extends NotificationProvider {
|
||||||
name = "pushbullet";
|
name = "pushbullet";
|
||||||
|
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
let okMsg = "Sent Successfully.";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let pushbulletUrl = "https://api.pushbullet.com/v2/pushes";
|
let pushbulletUrl = "https://api.pushbullet.com/v2/pushes";
|
||||||
|
@ -23,26 +22,26 @@ class Pushbullet extends NotificationProvider {
|
||||||
"type": "note",
|
"type": "note",
|
||||||
"title": "Uptime Kuma Alert",
|
"title": "Uptime Kuma Alert",
|
||||||
"body": "Testing Successful.",
|
"body": "Testing Successful.",
|
||||||
}
|
};
|
||||||
await axios.post(pushbulletUrl, testdata, config)
|
await axios.post(pushbulletUrl, testdata, config);
|
||||||
} else if (heartbeatJSON["status"] == DOWN) {
|
} else if (heartbeatJSON["status"] == DOWN) {
|
||||||
let downdata = {
|
let downdata = {
|
||||||
"type": "note",
|
"type": "note",
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
||||||
}
|
};
|
||||||
await axios.post(pushbulletUrl, downdata, config)
|
await axios.post(pushbulletUrl, downdata, config);
|
||||||
} else if (heartbeatJSON["status"] == UP) {
|
} else if (heartbeatJSON["status"] == UP) {
|
||||||
let updata = {
|
let updata = {
|
||||||
"type": "note",
|
"type": "note",
|
||||||
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
||||||
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
"body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"],
|
||||||
}
|
};
|
||||||
await axios.post(pushbulletUrl, updata, config)
|
await axios.post(pushbulletUrl, updata, 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 Pushbullet = require("./pushbullet");
|
const NotificationSend = require("../notification");
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// mockNodeMailer.createTransport.mockReset();
|
axios.post.mockReset();
|
||||||
});
|
});
|
||||||
|
const Pushbullet = require("./pushbullet");
|
||||||
|
|
||||||
describe("notification default information", () => {
|
describe("notification default information", () => {
|
||||||
it("should have the correct name", () => {
|
it("should have the correct name", () => {
|
||||||
|
@ -16,3 +17,185 @@ describe("notification default information", () => {
|
||||||
expect(notification.name).toBe("pushbullet");
|
expect(notification.name).toBe("pushbullet");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("notification to act properly on send", () => {
|
||||||
|
it("should call axios with the proper default data when UP", async () => {
|
||||||
|
|
||||||
|
let response = {
|
||||||
|
data: {
|
||||||
|
Message: "OK"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.post.mockResolvedValueOnce(response);
|
||||||
|
|
||||||
|
let notif = new Pushbullet();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "pushbullet",
|
||||||
|
pushbulletAccessToken: "token",
|
||||||
|
};
|
||||||
|
let monitorConf = {
|
||||||
|
name: "testing",
|
||||||
|
};
|
||||||
|
let heartbeatConf = {
|
||||||
|
status: UP,
|
||||||
|
msg: "some message",
|
||||||
|
time: "example time",
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
let res = await notif.send(notificationConf, msg, monitorConf, heartbeatConf);
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://api.pushbullet.com/v2/pushes", {
|
||||||
|
"body": "[✅ Up] some message\nTime (UTC): example time",
|
||||||
|
"title": "UptimeKuma Alert: testing",
|
||||||
|
"type": "note",
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Access-Token": "token",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
});
|
||||||
|
it("should call axios with the proper default data when UP", async () => {
|
||||||
|
|
||||||
|
let response = {
|
||||||
|
data: {
|
||||||
|
Message: "OK"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.post.mockResolvedValueOnce(response);
|
||||||
|
|
||||||
|
let notif = new Pushbullet();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "pushbullet",
|
||||||
|
pushbulletAccessToken: "token",
|
||||||
|
};
|
||||||
|
let monitorConf = {
|
||||||
|
name: "testing",
|
||||||
|
};
|
||||||
|
let heartbeatConf = {
|
||||||
|
status: DOWN,
|
||||||
|
msg: "some message",
|
||||||
|
time: "example time",
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
|
||||||
|
let res = await notif.send(notificationConf, msg, monitorConf, heartbeatConf);
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://api.pushbullet.com/v2/pushes", {
|
||||||
|
"body": "[🔴 Down] some message\nTime (UTC): example time",
|
||||||
|
"title": "UptimeKuma Alert: testing",
|
||||||
|
"type": "note",
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Access-Token": "token",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
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 Pushbullet();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "pushbullet",
|
||||||
|
pushbulletAccessToken: "token",
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
|
||||||
|
let res = await notif.send(notificationConf, msg, null, null);
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://api.pushbullet.com/v2/pushes", {
|
||||||
|
"body": "Testing Successful.",
|
||||||
|
"title": "Uptime Kuma Alert",
|
||||||
|
"type": "note",
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Access-Token": "token",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
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 Pushbullet();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "pushbullet",
|
||||||
|
pushbulletAccessToken: "token",
|
||||||
|
};
|
||||||
|
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://api.pushbullet.com/v2/pushes", {
|
||||||
|
"body": "Testing Successful.",
|
||||||
|
"title": "Uptime Kuma Alert",
|
||||||
|
"type": "note",
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Access-Token": "token",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
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: "pushbullet",
|
||||||
|
pushbulletAccessToken: "token",
|
||||||
|
};
|
||||||
|
let monitorConf = {
|
||||||
|
name: "testing",
|
||||||
|
};
|
||||||
|
let heartbeatConf = {
|
||||||
|
status: UP,
|
||||||
|
msg: "some message",
|
||||||
|
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.pushbullet.com/v2/pushes", {
|
||||||
|
"body": "[✅ Up] some message\nTime (UTC): example time",
|
||||||
|
"title": "UptimeKuma Alert: testing",
|
||||||
|
"type": "note",
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Access-Token": "token",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
@ -6,8 +6,7 @@ class Pushover extends NotificationProvider {
|
||||||
name = "pushover";
|
name = "pushover";
|
||||||
|
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
let okMsg = "Sent Successfully.";
|
let pushoverlink = "https://api.pushover.net/1/messages.json";
|
||||||
let pushoverlink = "https://api.pushover.net/1/messages.json"
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (heartbeatJSON == null) {
|
if (heartbeatJSON == null) {
|
||||||
|
@ -21,9 +20,9 @@ class Pushover extends NotificationProvider {
|
||||||
"retry": "30",
|
"retry": "30",
|
||||||
"expire": "3600",
|
"expire": "3600",
|
||||||
"html": 1,
|
"html": 1,
|
||||||
}
|
};
|
||||||
await axios.post(pushoverlink, data)
|
await axios.post(pushoverlink, data);
|
||||||
return okMsg;
|
return this.sendSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
|
@ -36,11 +35,11 @@ class Pushover extends NotificationProvider {
|
||||||
"retry": "30",
|
"retry": "30",
|
||||||
"expire": "3600",
|
"expire": "3600",
|
||||||
"html": 1,
|
"html": 1,
|
||||||
}
|
};
|
||||||
await axios.post(pushoverlink, data)
|
await axios.post(pushoverlink, data);
|
||||||
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 Pushover = require("./pushover");
|
const NotificationSend = require("../notification");
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// mockNodeMailer.createTransport.mockReset();
|
axios.post.mockReset();
|
||||||
});
|
});
|
||||||
|
const Pushover = require("./pushover");
|
||||||
|
|
||||||
describe("notification default information", () => {
|
describe("notification default information", () => {
|
||||||
it("should have the correct name", () => {
|
it("should have the correct name", () => {
|
||||||
|
@ -16,3 +17,125 @@ describe("notification default information", () => {
|
||||||
expect(notification.name).toBe("pushover");
|
expect(notification.name).toBe("pushover");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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 Pushover();
|
||||||
|
// let notificationConf = {
|
||||||
|
// type: "octopush",
|
||||||
|
// pushoveruserkey: "123",
|
||||||
|
// pushoverapptoken: "token",
|
||||||
|
// pushoversounds: "ding",
|
||||||
|
// pushoverpriority: "6",
|
||||||
|
// pushovertitle: "Important Title!",
|
||||||
|
// };
|
||||||
|
// let monitorConf = {
|
||||||
|
// };
|
||||||
|
// let heartbeatConf = {
|
||||||
|
// time: "example time",
|
||||||
|
// };
|
||||||
|
// let msg = "PassedInMessage😀";
|
||||||
|
// let res = await notif.send(notificationConf, msg, monitorConf, heartbeatConf);
|
||||||
|
|
||||||
|
// expect(axios.post).toHaveBeenCalledWith("", {
|
||||||
|
// });
|
||||||
|
// 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 Pushover();
|
||||||
|
// let notificationConf = {
|
||||||
|
// type: "octopush",
|
||||||
|
// pushoveruserkey: "123",
|
||||||
|
// pushoverapptoken: "token",
|
||||||
|
// pushoversounds: "ding",
|
||||||
|
// pushoverpriority: "6",
|
||||||
|
// pushovertitle: "Important Title!",
|
||||||
|
// };
|
||||||
|
// let msg = "PassedInMessage😀";
|
||||||
|
|
||||||
|
// let res = await notif.send(notificationConf, msg, null, null);
|
||||||
|
|
||||||
|
// expect(axios.post).toHaveBeenCalledWith("", {
|
||||||
|
// });
|
||||||
|
// 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 Pushover();
|
||||||
|
// let notificationConf = {
|
||||||
|
// type: "octopush",
|
||||||
|
// pushoveruserkey: "123",
|
||||||
|
// pushoverapptoken: "token",
|
||||||
|
// pushoversounds: "ding",
|
||||||
|
// pushoverpriority: "6",
|
||||||
|
// pushovertitle: "Important Title!",
|
||||||
|
// };
|
||||||
|
// 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("", {
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
||||||
|
// 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: "octopush",
|
||||||
|
// 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("", {
|
||||||
|
// });
|
||||||
|
// expect(res).toBe("Sent Successfully.");
|
||||||
|
// });
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
Loading…
Add table
Reference in a new issue