diff --git a/src/__tests__/webhooks/notification.spec.ts b/src/__tests__/webhooks/notification.spec.ts index 5a8c6a62d..2d2bf0d82 100644 --- a/src/__tests__/webhooks/notification.spec.ts +++ b/src/__tests__/webhooks/notification.spec.ts @@ -141,4 +141,29 @@ describe("Notification Tests", function (): void { expect(notificationRequestItem.additionalData["metadata.anotherKey"]).toEqual("anotherValue"); }); + +}); + +describe("NotificationRequestItem.additionalData", () => { + + it("handles undefined keys", () => { + const item = new NotificationRequestItem(); + item.additionalData = { + existingKey: "abc", + undefinedKey: undefined + }; + item.amount = { currency: "EUR", value: 1000 }; + item.pspReference = ""; + item.eventCode = NotificationRequestItem.EventCodeEnum.Authorisation; + item.eventDate = ""; + item.merchantAccountCode = ""; + item.merchantReference = ""; + item.success = NotificationRequestItem.SuccessEnum.True; + + expect(item.additionalData).toBeDefined(); + expect(item.additionalData).toHaveProperty("existingKey", "abc"); + expect(item.additionalData).toHaveProperty("undefinedKey", undefined); + expect(item.additionalData).not.toHaveProperty("nonExistingKey"); + }); + }); \ No newline at end of file diff --git a/src/typings/notification/notificationRequestItem.ts b/src/typings/notification/notificationRequestItem.ts index cdbaad77f..99ae21e11 100644 --- a/src/typings/notification/notificationRequestItem.ts +++ b/src/typings/notification/notificationRequestItem.ts @@ -32,7 +32,7 @@ import { Amount } from './amount'; export class NotificationRequestItem { - 'additionalData'?: { [key: string]: string; }; + 'additionalData'?: { [key: string]: string | undefined; }; 'amount': Amount; /** * Adyen\'s 16-character unique reference associated with the transaction/the request. This value is globally unique; quote it when communicating with us about this request.