mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-13 08:02:35 +02:00
promosms tests
This commit is contained in:
parent
6ce6d034a8
commit
d818ce866d
2 changed files with 185 additions and 11 deletions
|
@ -6,13 +6,12 @@ class PromoSMS extends NotificationProvider {
|
||||||
name = "promosms";
|
name = "promosms";
|
||||||
|
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
let okMsg = "Sent Successfully.";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let config = {
|
let config = {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString('base64'),
|
"Authorization": "Basic " + Buffer.from(notification.promosmsLogin + ":" + notification.promosmsPassword).toString("base64"),
|
||||||
"Accept": "text/json",
|
"Accept": "text/json",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -30,8 +29,8 @@ class PromoSMS extends NotificationProvider {
|
||||||
let error = "Something gone wrong. Api returned " + resp.data.response.status + ".";
|
let error = "Something gone wrong. Api returned " + resp.data.response.status + ".";
|
||||||
this.throwGeneralAxiosError(error);
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 PromoSMS = require("./promosms");
|
const NotificationSend = require("../notification");
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// mockNodeMailer.createTransport.mockReset();
|
axios.post.mockReset();
|
||||||
});
|
});
|
||||||
|
const PromoSMS = require("./promosms");
|
||||||
|
|
||||||
describe("notification default information", () => {
|
describe("notification default information", () => {
|
||||||
it("should have the correct name", () => {
|
it("should have the correct name", () => {
|
||||||
|
@ -16,3 +17,177 @@ describe("notification default information", () => {
|
||||||
expect(notification.name).toBe("promosms");
|
expect(notification.name).toBe("promosms");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("notification to act properly on send", () => {
|
||||||
|
it("should call axios with the proper default data", async () => {
|
||||||
|
|
||||||
|
let response = {
|
||||||
|
data: {
|
||||||
|
response: {
|
||||||
|
status: 0
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.post.mockResolvedValueOnce(response);
|
||||||
|
|
||||||
|
let notif = new PromoSMS();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "promosms",
|
||||||
|
promosmsLogin: "login",
|
||||||
|
promosmsPassword: "password",
|
||||||
|
promosmsPhoneNumber: "number",
|
||||||
|
promosmsSMSType: 1,
|
||||||
|
promosmsSenderName: "sender"
|
||||||
|
};
|
||||||
|
let monitorConf = {
|
||||||
|
};
|
||||||
|
let heartbeatConf = {
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
let res = await notif.send(notificationConf, msg, monitorConf, heartbeatConf);
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://promosms.com/api/rest/v3_2/sms", {
|
||||||
|
"recipients": [
|
||||||
|
"number",
|
||||||
|
],
|
||||||
|
"sender": "sender",
|
||||||
|
"text": "PassedInMessage",
|
||||||
|
"type": 1,
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Accept": "text/json",
|
||||||
|
"Authorization": "Basic bG9naW46cGFzc3dvcmQ=",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call axios with the proper data when monitor nil", async () => {
|
||||||
|
let response = {
|
||||||
|
data: {
|
||||||
|
response: {
|
||||||
|
status: 0
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.post.mockResolvedValueOnce(response);
|
||||||
|
|
||||||
|
let notif = new PromoSMS();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "promosms",
|
||||||
|
promosmsLogin: "login",
|
||||||
|
promosmsPassword: "password",
|
||||||
|
promosmsPhoneNumber: "number",
|
||||||
|
promosmsSMSType: 1,
|
||||||
|
promosmsSenderName: "sender"
|
||||||
|
};
|
||||||
|
let msg = "PassedInMessage😀";
|
||||||
|
|
||||||
|
let res = await notif.send(notificationConf, msg, null, null);
|
||||||
|
|
||||||
|
expect(axios.post).toHaveBeenCalledWith("https://promosms.com/api/rest/v3_2/sms", {
|
||||||
|
"recipients": [
|
||||||
|
"number",
|
||||||
|
],
|
||||||
|
"sender": "sender",
|
||||||
|
"text": "PassedInMessage",
|
||||||
|
"type": 1,
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Accept": "text/json",
|
||||||
|
"Authorization": "Basic bG9naW46cGFzc3dvcmQ=",
|
||||||
|
"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 PromoSMS();
|
||||||
|
let notificationConf = {
|
||||||
|
type: "promosms",
|
||||||
|
promosmsLogin: "login",
|
||||||
|
promosmsPassword: "password",
|
||||||
|
promosmsPhoneNumber: "number",
|
||||||
|
promosmsSMSType: 1,
|
||||||
|
promosmsSenderName: "sender"
|
||||||
|
};
|
||||||
|
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://promosms.com/api/rest/v3_2/sms", {
|
||||||
|
"recipients": [
|
||||||
|
"number",
|
||||||
|
],
|
||||||
|
"sender": "sender",
|
||||||
|
"text": "PassedInMessage",
|
||||||
|
"type": 1,
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Accept": "text/json",
|
||||||
|
"Authorization": "Basic bG9naW46cGFzc3dvcmQ=",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("notification to get proper data from Notification.send", () => {
|
||||||
|
it("should call axios with proper data", async () => {
|
||||||
|
let response = {
|
||||||
|
data: {
|
||||||
|
response: {
|
||||||
|
status: 0
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.post.mockResolvedValueOnce(response);
|
||||||
|
let notificationConf = {
|
||||||
|
type: "promosms",
|
||||||
|
promosmsLogin: "login",
|
||||||
|
promosmsPassword: "password",
|
||||||
|
promosmsPhoneNumber: "number",
|
||||||
|
promosmsSMSType: 1,
|
||||||
|
promosmsSenderName: "sender"
|
||||||
|
};
|
||||||
|
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://promosms.com/api/rest/v3_2/sms", {
|
||||||
|
"recipients": [
|
||||||
|
"number",
|
||||||
|
],
|
||||||
|
"sender": "sender",
|
||||||
|
"text": "PassedInMessage",
|
||||||
|
"type": 1,
|
||||||
|
}, {
|
||||||
|
"headers": {
|
||||||
|
"Accept": "text/json",
|
||||||
|
"Authorization": "Basic bG9naW46cGFzc3dvcmQ=",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue