@@ -311,4 +311,73 @@ describe("Notification Test", function (): void {
311
311
expect ( negativeBalanceCompensationWarningNotificationRequest . data . id ) . toBe ( "BA00000000000000000001" ) ;
312
312
expect ( negativeBalanceCompensationWarningNotificationRequest . data . creationDate ?. toISOString ( ) ) . toBe ( new Date ( "2024-07-02T02:01:08+02:00" ) . toISOString ( ) ) ;
313
313
} ) ;
314
+
315
+ it ( "should correctly deserialize notificationItems and handle additionalData.metadata" , ( ) => {
316
+ // Scenario 1: Valid metadata with string values
317
+ const validNotification = {
318
+ live : "true" ,
319
+ notificationItems : [
320
+ {
321
+ NotificationRequestItem : {
322
+ pspReference : "123456789" ,
323
+ eventCode : "AUTHORISATION" ,
324
+ eventDate : "2021-01-01T00:00:00+00:00" ,
325
+ merchantAccountCode : "TestAccount" ,
326
+ merchantReference : "TestRef" ,
327
+ success : "true" ,
328
+ amount : { currency : "EUR" , value : 100 } ,
329
+ additionalData : {
330
+ metadata : {
331
+ key1 : "value1" ,
332
+ key2 : "value2"
333
+ }
334
+ }
335
+ }
336
+ }
337
+ ]
338
+ } ;
339
+
340
+ const validRequest = new NotificationRequest ( validNotification as any ) ;
341
+ const validItem = validRequest . notificationItems ! [ 0 ] ;
342
+ const validMetadata = validItem . additionalData ?. metadata as unknown as Record < string , string > ;
343
+ expect ( validMetadata ) . toEqual ( {
344
+ key1 : "value1" ,
345
+ key2 : "value2"
346
+ } ) ;
347
+
348
+ // Scenario 2: Metadata containing a nested object (which is not a plain string)
349
+ const invalidNotification = {
350
+ live : "true" ,
351
+ notificationItems : [
352
+ {
353
+ NotificationRequestItem : {
354
+ pspReference : "123456789" ,
355
+ eventCode : "AUTHORISATION" ,
356
+ eventDate : "2021-01-01T00:00:00+00:00" ,
357
+ merchantAccountCode : "TestAccount" ,
358
+ merchantReference : "TestRef" ,
359
+ success : "true" ,
360
+ amount : { currency : "EUR" , value : 100 } ,
361
+ additionalData : {
362
+ metadata : {
363
+ key1 : { nestedKey : "nestedValue" }
364
+ }
365
+ }
366
+ }
367
+ }
368
+ ]
369
+ } ;
370
+
371
+ const invalidRequest = new NotificationRequest ( invalidNotification as any ) ;
372
+ // type expects string, check that the value is not a string, accepts nested?
373
+ // Get the first notification item from the invalidRequest.
374
+ const invalidItem = invalidRequest . notificationItems ! [ 0 ] ;
375
+ const additionalData = invalidItem . additionalData ;
376
+ const metadata = additionalData ? additionalData . metadata : undefined ;
377
+ const key1Value = metadata ? metadata [ "key1" ] : undefined ;
378
+ const key1ValueType = typeof key1Value ;
379
+ // Assert that the type of key1Value is not "string".
380
+ expect ( key1ValueType ) . not . toBe ( "string" ) ;
381
+ } ) ;
382
+
314
383
} ) ;
0 commit comments