11const MailgunEmailProvider = require ( '../../../../../core/server/services/email-service/mailgun-email-provider' ) ;
22const sinon = require ( 'sinon' ) ;
3- const should = require ( 'should' ) ;
43const assert = require ( 'assert/strict' ) ;
54
65describe ( 'Mailgun Email Provider' , function ( ) {
@@ -62,9 +61,9 @@ describe('Mailgun Email Provider', function () {
6261 openTrackingEnabled : true ,
6362 deliveryTime
6463 } ) ;
65- should ( response . id ) . eql ( 'provider-123' ) ;
66- should ( sendStub . calledOnce ) . be . true ( ) ;
67- sendStub . calledWith (
64+ assert . equal ( response . id , 'provider-123' ) ;
65+ sinon . assert . calledOnce ( sendStub ) ;
66+ sinon . assert . calledWith ( sendStub ,
6867 {
6968 subject : 'Hi' ,
7069 html : '<html><body>Hi %recipient.name%</body></html>' ,
@@ -79,7 +78,7 @@ describe('Mailgun Email Provider', function () {
7978 } ,
8079 { '[email protected] ' :
{ name :
'John' } } , 8180 [ ]
82- ) . should . be . true ( ) ;
81+ ) ;
8382 } ) ;
8483
8584 it ( 'handles mailgun client error correctly' , async function ( ) {
@@ -99,8 +98,8 @@ describe('Mailgun Email Provider', function () {
9998 mailgunClient,
10099 errorHandler : ( ) => { }
101100 } ) ;
102- try {
103- const response = await mailgunEmailProvider . send ( {
101+ await assert . rejects ( async ( ) => {
102+ await mailgunEmailProvider . send ( {
104103 subject : 'Hi' ,
105104 html : '<html><body>Hi {{name}}</body></html>' ,
106105 plaintext : 'Hi' ,
@@ -127,12 +126,12 @@ describe('Mailgun Email Provider', function () {
127126 }
128127 ]
129128 } , { } ) ;
130- should ( response ) . be . undefined ( ) ;
131- } catch ( e ) {
132- should ( e . message ) . eql ( 'Bad Request: Invalid domain' ) ;
133- should ( e . statusCode ) . eql ( 400 ) ;
134- should ( e . errorDetails ) . eql ( '{"error":{"details":"Invalid domain","status":400},"messageData":{}}' ) ;
135- }
129+ assert . fail ( ) ;
130+ } , {
131+ message : 'Bad Request: Invalid domain' ,
132+ statusCode : 400 ,
133+ errorDetails : '{"error":{"details":"Invalid domain","status":400},"messageData":{}}'
134+ } ) ;
136135 } ) ;
137136
138137 it ( 'handles unknown error correctly' , async function ( ) {
@@ -147,8 +146,8 @@ describe('Mailgun Email Provider', function () {
147146 mailgunClient,
148147 errorHandler : ( ) => { }
149148 } ) ;
150- try {
151- const response = await mailgunEmailProvider . send ( {
149+ await assert . rejects ( async ( ) => {
150+ await mailgunEmailProvider . send ( {
152151 subject : 'Hi' ,
153152 html : '<html><body>Hi {{name}}</body></html>' ,
154153 plaintext : 'Hi' ,
@@ -175,11 +174,11 @@ describe('Mailgun Email Provider', function () {
175174 }
176175 ]
177176 } , { } ) ;
178- should ( response ) . be . undefined ( ) ;
179- } catch ( e ) {
180- should ( e . message ) . eql ( 'Unknown Error' ) ;
181- should ( e . errorDetails ) . eql ( undefined ) ;
182- }
177+ assert . fail ( ) ;
178+ } , {
179+ message : 'Unknown Error' ,
180+ errorDetails : undefined
181+ } ) ;
183182 } ) ;
184183
185184 it ( 'handles empty error correctly' , async function ( ) {
@@ -194,8 +193,8 @@ describe('Mailgun Email Provider', function () {
194193 mailgunClient,
195194 errorHandler : ( ) => { }
196195 } ) ;
197- try {
198- const response = await mailgunEmailProvider . send ( {
196+ await assert . rejects ( async ( ) => {
197+ await mailgunEmailProvider . send ( {
199198 subject : 'Hi' ,
200199 html : '<html><body>Hi {{name}}</body></html>' ,
201200 plaintext : 'Hi' ,
@@ -222,11 +221,11 @@ describe('Mailgun Email Provider', function () {
222221 }
223222 ]
224223 } , { } ) ;
225- should ( response ) . be . undefined ( ) ;
226- } catch ( e ) {
227- should ( e . message ) . eql ( 'Mailgun Error' ) ;
228- should ( e . errorDetails ) . eql ( undefined ) ;
229- }
224+ assert . fail ( ) ;
225+ } , {
226+ message : 'Mailgun Error' ,
227+ errorDetails : undefined
228+ } ) ;
230229 } ) ;
231230 } ) ;
232231
0 commit comments