@@ -2,7 +2,7 @@ const { getStorageConnection } = require('../../lib/main/server/storageConnectio
22const axios = require ( 'axios' ) ;
33const nodemailer = require ( 'nodemailer' ) ;
44const { EmailService, SlackService, testSlackAlert, testEmailAlert, clearEmailTransport, customLoggerAlert, handleUncaughtExceptions } = require ( '../../lib/main/server/utils/alerts' ) ; // Adjust the path as needed
5- /* globals expect, jest, beforeEach, describe, beforeAll, afterAll, it, afterEach */
5+ /* globals expect, jest, beforeEach, describe, beforeAll, afterAll, it, afterEach */
66
77jest . mock ( 'axios' ) ;
88jest . mock ( 'nodemailer' ) ;
@@ -110,11 +110,12 @@ describe('EmailService', () => {
110110
111111 const result = await EmailService . sendAlert ( 'Test message' , 'Test type' , { appName : 'TestApp' , environmentName : 'TestEnv' } ) ;
112112
113+ // Use a regular expression to match the 'html' content, allowing for flexible whitespace
113114 expect ( mockTransporter . sendMail ) . toHaveBeenCalledWith ( expect . objectContaining ( {
114115115116116117 subject : 'Errsole: Test type (TestApp app, TestEnv environment)' ,
117- html : ' <p><b>App Name: TestApp\nEnvironment Name: TestEnv< /b>< /p><br/><pre style="border: 1px solid #ccc; background-color: #f9f9f9; padding: 10px;">Test message</pre>'
118+ html : expect . stringMatching ( / < p > < b > A p p N a m e : < \/ b > T e s t A p p < \/ p > \s * < p > < b > E n v i r o n m e n t N a m e : < \ /b > T e s t E n v < \ /p > < b r \ /> < p r e s t y l e = " b o r d e r : 1 p x s o l i d # c c c ; b a c k g r o u n d - c o l o r : # f 9 f 9 f 9 ; p a d d i n g : 1 0 p x ; " > T e s t m e s s a g e < \ /p r e > / )
118119 } ) ) ;
119120 expect ( result ) . toBe ( true ) ;
120121 } ) ;
@@ -185,7 +186,7 @@ describe('EmailService', () => {
185186186187187188 subject : 'Errsole: Test type (TestApp app, TestEnv environment)' ,
188- html : ' <p><b>App Name: TestApp\nEnvironment Name: TestEnv< /b>< /p><br/><pre style="border: 1px solid #ccc; background-color: #f9f9f9; padding: 10px;">Test message</pre>'
189+ html : expect . stringMatching ( / < p > < b > A p p N a m e : < \/ b > T e s t A p p < \/ p > \s * < p > < b > E n v i r o n m e n t N a m e : < \ /b > T e s t E n v < \ /p > < b r \ /> < p r e s t y l e = " b o r d e r : 1 p x s o l i d # c c c ; b a c k g r o u n d - c o l o r : # f 9 f 9 f 9 ; p a d d i n g : 1 0 p x ; " > T e s t m e s s a g e < \ /p r e > / )
189190 } ) ) ;
190191 } ) ;
191192
@@ -217,7 +218,7 @@ describe('EmailService', () => {
217218218219219220 subject : 'Errsole: Test type (TestApp app)' ,
220- html : ' <p><b>App Name: TestApp< /b>< /p><br/><pre style="border: 1px solid #ccc; background-color: #f9f9f9; padding: 10px;">Test message</pre>'
221+ html : expect . stringMatching ( / < p > < b > A p p N a m e : < \ /b > T e s t A p p < \ /p > < b r \ /> < p r e s t y l e = " b o r d e r : 1 p x s o l i d # c c c ; b a c k g r o u n d - c o l o r : # f 9 f 9 f 9 ; p a d d i n g : 1 0 p x ; " > T e s t m e s s a g e < \ /p r e > / )
221222 } ) ) ;
222223 } ) ;
223224
@@ -249,7 +250,7 @@ describe('EmailService', () => {
249250250251251252 subject : 'Errsole: Test type (TestEnv environment)' ,
252- html : ' <p><b>Environment Name: TestEnv< /b>< /p><br/><pre style="border: 1px solid #ccc; background-color: #f9f9f9; padding: 10px;">Test message</pre>'
253+ html : expect . stringMatching ( / < p > < b > E n v i r o n m e n t N a m e : < \ /b > T e s t E n v < \ /p > < b r \ /> < p r e s t y l e = " b o r d e r : 1 p x s o l i d # c c c ; b a c k g r o u n d - c o l o r : # f 9 f 9 f 9 ; p a d d i n g : 1 0 p x ; " > T e s t m e s s a g e < \ /p r e > / )
253254 } ) ) ;
254255 } ) ;
255256
@@ -379,6 +380,7 @@ describe('SlackService', () => {
379380 } ) ;
380381
381382 const result = await SlackService . sendAlert ( 'Test message' , 'Test type' , { } ) ;
383+
382384 expect ( console . error ) . toHaveBeenCalledWith ( 'Failed to send slack alert:' , expect . any ( Error ) ) ;
383385 expect ( result ) . toBe ( false ) ;
384386 } ) ;
@@ -390,6 +392,7 @@ describe('SlackService', () => {
390392 mockStorageConnection . getConfig . mockResolvedValue ( mockConfig ) ;
391393
392394 const result = await SlackService . sendAlert ( 'Test message' , 'Test type' , { } ) ;
395+
393396 expect ( result ) . toBe ( false ) ;
394397 } ) ;
395398} ) ;
0 commit comments