@@ -175,7 +175,7 @@ describe("Modification", (): void => {
175
175
} ) ;
176
176
177
177
test ( "should fail to perform an amount update request" , async ( ) : Promise < void > => {
178
- expect . assertions ( 2 ) ;
178
+ expect . assertions ( 4 ) ;
179
179
const request = createAmountUpdateRequest ( ) ;
180
180
scope . post ( `/payments/${ invalidPaymentPspReference } /amountUpdates` )
181
181
. reply ( 422 , invalidModificationResult ) ;
@@ -184,8 +184,11 @@ describe("Modification", (): void => {
184
184
await checkoutAPI . ModificationsApi . updateAuthorisedAmount ( invalidPaymentPspReference , request ) ;
185
185
} catch ( e ) {
186
186
if ( e instanceof HttpClientException ) {
187
- if ( e . statusCode ) expect ( e . statusCode ) . toBe ( 422 ) ;
187
+ expect ( e . statusCode ) . toBe ( 422 ) ;
188
188
expect ( e . message ) . toContain ( "Original pspReference required for this operation" ) ;
189
+ // check API apiError
190
+ expect ( e . apiError ) . toBeTruthy ( ) ;
191
+ expect ( e . apiError ?. status ) . toBe ( 422 ) ;
189
192
} else {
190
193
fail ( ) ;
191
194
}
@@ -209,16 +212,20 @@ describe("Modification", (): void => {
209
212
} ) ;
210
213
211
214
test ( "should fail to perform a cancels request" , async ( ) : Promise < void > => {
212
- expect . assertions ( 2 ) ;
215
+ expect . assertions ( 4 ) ;
213
216
const request = createCancelsRequest ( ) ;
214
217
scope . post ( `/payments/${ invalidPaymentPspReference } /cancels` )
215
218
. reply ( 422 , invalidModificationResult ) ;
216
219
try {
217
220
await checkoutAPI . ModificationsApi . cancelAuthorisedPaymentByPspReference ( invalidPaymentPspReference , request ) ;
218
221
} catch ( e ) {
219
222
if ( e instanceof HttpClientException ) {
220
- if ( e . statusCode ) expect ( e . statusCode ) . toBe ( 422 ) ;
223
+ expect ( e . statusCode ) . toBe ( 422 ) ;
221
224
expect ( e . message ) . toContain ( "Original pspReference required for this operation" ) ;
225
+ // check apiError
226
+ expect ( e . apiError ) . toBeTruthy ( ) ;
227
+ expect ( e . apiError ?. errorCode ) . toBe ( "167" ) ;
228
+
222
229
} else {
223
230
fail ( ) ;
224
231
}
@@ -258,16 +265,19 @@ describe("Modification", (): void => {
258
265
} ) ;
259
266
260
267
test ( "should fail to perform a captures request" , async ( ) : Promise < void > => {
261
- expect . assertions ( 2 ) ;
268
+ expect . assertions ( 4 ) ;
262
269
const request = createCapturesRequest ( ) ;
263
270
scope . post ( `/payments/${ invalidPaymentPspReference } /captures` )
264
271
. reply ( 422 , invalidModificationResult ) ;
265
272
try {
266
273
await checkoutAPI . ModificationsApi . captureAuthorisedPayment ( invalidPaymentPspReference , request ) ;
267
274
} catch ( e ) {
268
275
if ( e instanceof HttpClientException ) {
269
- if ( e . statusCode ) expect ( e . statusCode ) . toBe ( 422 ) ;
276
+ expect ( e . statusCode ) . toBe ( 422 ) ;
270
277
expect ( e . message ) . toContain ( "Original pspReference required for this operation" ) ;
278
+ // check apiError
279
+ expect ( e . apiError ) . toBeTruthy ( ) ;
280
+ expect ( e . apiError ?. errorCode ) . toBe ( "167" ) ;
271
281
} else {
272
282
fail ( ) ;
273
283
}
@@ -324,16 +334,19 @@ describe("Modification", (): void => {
324
334
} ) ;
325
335
326
336
test ( "should fail to perform a reversals request" , async ( ) : Promise < void > => {
327
- expect . assertions ( 2 ) ;
337
+ expect . assertions ( 4 ) ;
328
338
const request = createReversalsRequest ( ) ;
329
339
scope . post ( `/payments/${ invalidPaymentPspReference } /reversals` )
330
340
. reply ( 422 , invalidModificationResult ) ;
331
341
try {
332
342
await checkoutAPI . ModificationsApi . refundOrCancelPayment ( invalidPaymentPspReference , request ) ;
333
343
} catch ( e ) {
334
344
if ( e instanceof HttpClientException ) {
335
- if ( e . statusCode ) expect ( e . statusCode ) . toBe ( 422 ) ;
345
+ expect ( e . statusCode ) . toBe ( 422 ) ;
336
346
expect ( e . message ) . toContain ( "Original pspReference required for this operation" ) ;
347
+ // check apiError
348
+ expect ( e . apiError ) . toBeTruthy ( ) ;
349
+ expect ( e . apiError ?. errorCode ) . toBe ( "167" ) ;
337
350
} else {
338
351
fail ( ) ;
339
352
}
0 commit comments