@@ -91,4 +91,52 @@ describe("Notification Tests", function (): void {
9191 }
9292 } ) ;
9393
94+ it ( "should return notification items with additional data as key-value map" , function ( ) : void {
95+ const notificationRequestItem = new NotificationRequestItem ( ) ;
96+
97+ notificationRequestItem . amount = { currency : "EUR" , value : 1000 } ;
98+ notificationRequestItem . pspReference = "123456789" ;
99+ notificationRequestItem . eventCode = NotificationEnum . Authorisation ;
100+ notificationRequestItem . eventDate = "2023-10-01T12:00:00+00:00" ;
101+ notificationRequestItem . merchantAccountCode = "TestMerchant" ;
102+ notificationRequestItem . merchantReference = "TestReference" ;
103+ notificationRequestItem . success = SuccessEnum . True ;
104+ notificationRequestItem . additionalData = {
105+ orderId : "12345" ,
106+ customerId : "67890"
107+ } ;
108+
109+ expect ( notificationRequestItem . amount ) . toBeDefined ( ) ;
110+ expect ( notificationRequestItem . additionalData ) . toBeDefined ( ) ;
111+ expect ( notificationRequestItem . additionalData ! . orderId ) . toEqual ( "12345" ) ;
112+ expect ( notificationRequestItem . additionalData ! . customerId ) . toEqual ( "67890" ) ;
113+
114+ } ) ;
115+
116+ // test additionanDalata with medata as key-value pairs prefixed with "metadata." i.e. "metadata.myKey": "myValue"
117+ it ( "should return notification items with additional data as key-value object" , function ( ) : void {
118+ const notificationRequestItem = new NotificationRequestItem ( ) ;
119+
120+ notificationRequestItem . amount = { currency : "EUR" , value : 1000 } ;
121+ notificationRequestItem . pspReference = "123456789" ;
122+ notificationRequestItem . eventCode = NotificationEnum . Authorisation ;
123+ notificationRequestItem . eventDate = "2023-10-01T12:00:00+00:00" ;
124+ notificationRequestItem . merchantAccountCode = "TestMerchant" ;
125+ notificationRequestItem . merchantReference = "TestReference" ;
126+ notificationRequestItem . success = SuccessEnum . True ;
127+ notificationRequestItem . additionalData = {
128+ orderId : "12345" ,
129+ customerId : "67890" ,
130+ "metadata.myKey" : "myValue" ,
131+ "metadata.anotherKey" : "anotherValue"
132+ } ;
133+
134+ expect ( notificationRequestItem . amount ) . toBeDefined ( ) ;
135+ expect ( notificationRequestItem . additionalData ) . toBeDefined ( ) ;
136+ expect ( notificationRequestItem . additionalData ! . orderId ) . toEqual ( "12345" ) ;
137+ expect ( notificationRequestItem . additionalData ! . customerId ) . toEqual ( "67890" ) ;
138+ expect ( notificationRequestItem . additionalData ! [ "metadata.myKey" ] ) . toEqual ( "myValue" ) ;
139+ expect ( notificationRequestItem . additionalData ! [ "metadata.anotherKey" ] ) . toEqual ( "anotherValue" ) ;
140+
141+ } ) ;
94142} ) ;
0 commit comments