-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@dhealthdapps/backend] test(notifier): update & fix failed unit tests
- Loading branch information
Showing
2 changed files
with
49 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,6 @@ describe("notifier/AlertNotifier", () => { | |
DappHelper, // requirement from AlertNotifier | ||
NotifierFactory, // requirement from AlertNotifier | ||
EmailNotifier, // requirement from AlertNotifier | ||
ConfigService, // requirement from DappHelper | ||
NetworkService, // requirement from DappHelper | ||
MailerService, // requirement from EmailNotifier | ||
{ | ||
|
@@ -118,16 +117,16 @@ describe("notifier/AlertNotifier", () => { | |
jest.clearAllMocks(); | ||
(service as any).alertsConfig = { | ||
type: ["warn"], | ||
transport: "mail", | ||
recipient: "[email protected]", | ||
}; | ||
const configServiceGetCall = jest | ||
.spyOn(configService, "get") | ||
.mockReturnValue("test-name"); | ||
.mockReturnValueOnce("test-dapp-name") | ||
.mockReturnValueOnce("test-url"); | ||
const notifierSendInternalCall = jest | ||
.spyOn(notifier, "sendInternal") | ||
.mockResolvedValue(); | ||
const dappHelperCreateDetailsTableHTMLCall = jest | ||
.spyOn(dappHelper, "createDetailsTableHTML") | ||
.mockReturnValue("test-html-content"); | ||
const alertEvent: AlertEvent = { | ||
timestamp: new Date(), | ||
level: "warn", | ||
|
@@ -141,8 +140,23 @@ describe("notifier/AlertNotifier", () => { | |
|
||
// assert | ||
expect(configServiceGetCall).toHaveBeenNthCalledWith(1, "dappName"); | ||
expect(dappHelperCreateDetailsTableHTMLCall).toHaveBeenNthCalledWith(1, [alertEvent]); | ||
expect(notifierSendInternalCall).toHaveBeenCalledTimes(1); | ||
expect(notifierSendInternalCall).toHaveBeenNthCalledWith(1, { | ||
to: "[email protected]", | ||
subject: "[test-dapp-name] WARNING on dApp (test-url) at 1212-02-01 12:00:00", | ||
context: { | ||
alertLevel: "WARNING", | ||
dappUrl: "test-url", | ||
dateFormat: "1212-02-01 12:00:00", | ||
details: { | ||
context: "test-context", | ||
level: "warn", | ||
loggerContext: "test-logger-context", | ||
message: "test-message", | ||
timestamp: new Date(), | ||
}, | ||
}, | ||
template: "AlertEmailTemplate", | ||
}); | ||
}); | ||
}); | ||
|
||
|
@@ -159,9 +173,6 @@ describe("notifier/AlertNotifier", () => { | |
const notifierSendInternalCall = jest | ||
.spyOn(notifier, "sendInternal") | ||
.mockResolvedValue(); | ||
const dappHelperCreateDetailsTableHTMLCall = jest | ||
.spyOn(dappHelper, "createDetailsTableHTML") | ||
.mockReturnValue("test-html-content"); | ||
const alertEvent: AlertEvent = AlertEvent.create( | ||
new Date(), | ||
"error", | ||
|
@@ -176,7 +187,6 @@ describe("notifier/AlertNotifier", () => { | |
|
||
// assert | ||
expect(configServiceGetCall).toHaveBeenCalledTimes(0); | ||
expect(dappHelperCreateDetailsTableHTMLCall).toHaveBeenCalledTimes(0); | ||
expect(notifierSendInternalCall).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
|
@@ -185,16 +195,15 @@ describe("notifier/AlertNotifier", () => { | |
jest.clearAllMocks(); | ||
(service as any).alertsConfig = { | ||
type: ["error"], | ||
transport: "mail", | ||
recipient: "[email protected]", | ||
}; | ||
const configServiceGetCall = jest | ||
.spyOn(configService, "get") | ||
.mockReturnValue("test-name"); | ||
const notifierSendInternalCall = jest | ||
.spyOn(notifier, "sendInternal") | ||
.mockResolvedValue(); | ||
const dappHelperCreateDetailsTableHTMLCall = jest | ||
.spyOn(dappHelper, "createDetailsTableHTML") | ||
.mockReturnValue("test-html-content"); | ||
const alertEvent: AlertEvent = { | ||
timestamp: new Date(), | ||
level: "error", | ||
|
@@ -209,8 +218,24 @@ describe("notifier/AlertNotifier", () => { | |
|
||
// assert | ||
expect(configServiceGetCall).toHaveBeenNthCalledWith(1, "dappName"); | ||
expect(dappHelperCreateDetailsTableHTMLCall).toHaveBeenNthCalledWith(1, [alertEvent]); | ||
expect(notifierSendInternalCall).toHaveBeenCalledTimes(1); | ||
expect(notifierSendInternalCall).toHaveBeenNthCalledWith(1, { | ||
to: "[email protected]", | ||
subject: "[test-name] ERROR on dApp (test-name) at 1212-02-01 12:00:00", | ||
context: { | ||
alertLevel: "ERROR", | ||
dappUrl: "test-name", | ||
dateFormat: "1212-02-01 12:00:00", | ||
details: { | ||
context: "test-context", | ||
level: "error", | ||
loggerContext: "test-logger-context", | ||
message: "test-message", | ||
timestamp: new Date(), | ||
trace: "test-trace", | ||
}, | ||
}, | ||
template: "AlertEmailTemplate", | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,8 +344,14 @@ describe("notifier/ReportNotifier", () => { | |
{ | ||
to: "[email protected]", | ||
subject: `[test-dapp-name] LOGS REPORT for dApp (test-url) from ${dateStart} to ${dateEnd}`, | ||
text: `The production logs for test-dapp-name (test-url) from ${dateStart} to ${dateEnd} can be found as an attachment to this email.`, | ||
html: `The production logs for test-dapp-name (test-url) from <b>${dateStart}</b> to <b>${dateEnd}</b> can be found as an attachment to this email.`, | ||
context: { | ||
alertLevel: "WARNING", | ||
dappName: "test-dapp-name", | ||
dappUrl: "test-url", | ||
dateEnd: "2022-02-01", | ||
dateStart: "2022-02-01", | ||
}, | ||
template: "ReportEmailTemplate", | ||
attachments: [ | ||
{ | ||
// binary buffer as an attachment | ||
|