Skip to content

Commit 25b00a2

Browse files
committed
Adjust tests
1 parent 4200591 commit 25b00a2

File tree

1 file changed

+30
-109
lines changed

1 file changed

+30
-109
lines changed

src/__tests__/notification.spec.ts

Lines changed: 30 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ import captureTrue from "../__mocks__/notification/captureTrue.json";
33
import captureFalse from "../__mocks__/notification/captureFalse.json";
44
import refundTrue from "../__mocks__/notification/refundTrue.json";
55
import refundFalse from "../__mocks__/notification/refundFalse.json";
6-
import NotificationRequest from "../notification/notificationRequest";
7-
import { Notification, NotificationRequestItem } from "../typings/notification/models";
6+
87
import NotificationEnum = NotificationRequestItem.EventCodeEnum;
98
import SuccessEnum = NotificationRequestItem.SuccessEnum;
10-
import BankingWebhookHandler from "../notification/bankingWebhookHandler";
11-
import {AccountHolderNotificationRequest} from "../typings/configurationWebhooks/accountHolderNotificationRequest";
12-
import {BalanceAccountNotificationRequest} from "../typings/configurationWebhooks/balanceAccountNotificationRequest";
13-
import HmacValidator from "../utils/hmacValidator";
14-
import ManagementWebhookHandler from "../notification/managementWebhookHandler";
15-
import {
16-
PaymentMethodCreatedNotificationRequest
17-
} from "../typings/managementWebhooks/paymentMethodCreatedNotificationRequest";
18-
import {MerchantUpdatedNotificationRequest} from "../typings/managementWebhooks/merchantUpdatedNotificationRequest";
19-
import {AuthenticationNotificationRequest} from "../typings/acsWebhooks/authenticationNotificationRequest";
20-
import {TransferNotificationRequest} from "../typings/transferWebhooks/transferNotificationRequest";
9+
10+
// requests
11+
import NotificationRequest from "../notification/notificationRequest";
12+
import { Notification, NotificationRequestItem } from "../typings/notification/models";
13+
import { AccountHolderNotificationRequest } from "../typings/configurationWebhooks/accountHolderNotificationRequest";
14+
import { BalanceAccountNotificationRequest } from "../typings/configurationWebhooks/balanceAccountNotificationRequest";
15+
import { PaymentMethodCreatedNotificationRequest } from "../typings/managementWebhooks/paymentMethodCreatedNotificationRequest";
16+
import { MerchantUpdatedNotificationRequest } from "../typings/managementWebhooks/merchantUpdatedNotificationRequest";
17+
import { AuthenticationNotificationRequest } from "../typings/acsWebhooks/authenticationNotificationRequest";
18+
import { TransferNotificationRequest } from "../typings/transferWebhooks/transferNotificationRequest";
2119
import { PaymentMethodRequestRemovedNotificationRequest } from "../typings/managementWebhooks/paymentMethodRequestRemovedNotificationRequest";
2220
import { PaymentMethodScheduledForRemovalNotificationRequest } from "../typings/managementWebhooks/paymentMethodScheduledForRemovalNotificationRequest";
2321
import { TransactionNotificationRequestV4 } from "../typings/transactionWebhooks/transactionNotificationRequestV4";
2422
import { NegativeBalanceCompensationWarningNotificationRequest } from "../typings/negativeBalanceWarningWebhooks/negativeBalanceCompensationWarningNotificationRequest";
2523
import { BalanceAccountBalanceNotificationRequest } from "../typings/balanceWebhooks/balanceAccountBalanceNotificationRequest";
24+
25+
// handlers
2626
import { AcsWebhooksHandler } from "../typings/acsWebhooks/acsWebhooksHandler";
2727
import { ReportWebhooksHandler } from "../typings/reportWebhooks/reportWebhooksHandler";
2828
import { ConfigurationWebhooksHandler } from "../typings/configurationWebhooks/configurationWebhooksHandler";
@@ -31,6 +31,9 @@ import { NegativeBalanceWarningWebhooksHandler } from "../typings/negativeBalanc
3131
import { TransactionWebhooksHandler } from "../typings/transactionWebhooks/transactionWebhooksHandler";
3232
import { BalanceWebhooksHandler } from "../typings/balanceWebhooks/balanceWebhooksHandler";
3333
import { ReportNotificationRequest } from "../typings/reportWebhooks/reportNotificationRequest";
34+
import { ManagementWebhooksHandler } from "../typings/managementWebhooks/managementWebhooksHandler";
35+
36+
import HmacValidator from "../utils/hmacValidator";
3437

3538
describe("Notification Test", function (): void {
3639

@@ -230,65 +233,14 @@ describe("Notification Test", function (): void {
230233
"type": "paymentMethod.created"
231234
};
232235
const jsonString = JSON.stringify(json);
233-
const managementWebhookHandler = new ManagementWebhookHandler(jsonString);
234-
const paymentMethodCreatedNotificationRequest: PaymentMethodCreatedNotificationRequest = managementWebhookHandler.getPaymentMethodCreatedNotificationRequest();
235-
const genericWebhook = managementWebhookHandler.getGenericWebhook();
236+
const managementWebhooksHandler = new ManagementWebhooksHandler(jsonString);
237+
const paymentMethodCreatedNotificationRequest: PaymentMethodCreatedNotificationRequest = managementWebhooksHandler.getPaymentMethodCreatedNotificationRequest();
238+
const genericWebhook = managementWebhooksHandler.getGenericWebhook();
236239
expect(genericWebhook instanceof PaymentMethodCreatedNotificationRequest).toBe(true);
237240
expect(genericWebhook instanceof MerchantUpdatedNotificationRequest).toBe(false);
238241
expect(paymentMethodCreatedNotificationRequest.type).toEqual(PaymentMethodCreatedNotificationRequest.TypeEnum.PaymentMethodCreated);
239242
});
240243

241-
it("should deserialize Banking Authentication Webhook", function (): void {
242-
const json = {
243-
"data": {
244-
"balancePlatform": "YOUR_BALANCE_PLATFORM",
245-
"creationDate": "2023-01-19T17:07:59+01:00",
246-
"id": "a8fc7a40-6e48-498a-bdc2-494daf0f490a",
247-
"authentication": {
248-
"acsTransId": "a8fc7a40-6e48-498a-bdc2-494daf0f490a",
249-
"challenge": {
250-
"flow": "OTP_SMS",
251-
"lastInteraction": "2023-01-19T17:37:13+01:00",
252-
"phoneNumber": "******6789",
253-
"resends": 0,
254-
"retries": 2
255-
},
256-
"challengeIndicator": "01",
257-
"createdAt": "2023-01-19T17:07:17+01:00",
258-
"deviceChannel": "app",
259-
"dsTransID": "59de4e30-7f84-4a77-aaf8-1ca493092ef9",
260-
"exemptionIndicator": "noExemptionApplied",
261-
"inPSD2Scope": false,
262-
"messageCategory": "payment",
263-
"messageVersion": "2.2.0",
264-
"threeDSServerTransID": "8bc0fdbd-5c8a-4bed-a171-9d10347e7798",
265-
"transStatus": "N",
266-
"transStatusReason": "19",
267-
"type": "challenge"
268-
},
269-
"paymentInstrumentId": "PI3227C223222B5BPCMFXD2XG",
270-
"purchase": {
271-
"date": "2022-12-22T15:49:03+01:00",
272-
"merchantName": "TeaShop_NL",
273-
"originalAmount": {
274-
"currency": "EUR",
275-
"value": 1000
276-
}
277-
},
278-
"status": "rejected"
279-
},
280-
"environment": "test",
281-
"type": "balancePlatform.authentication.created"
282-
};
283-
const jsonString = JSON.stringify(json);
284-
const bankingWebhookHandler = new BankingWebhookHandler(jsonString);
285-
const accountHolderNotificationRequest: TransferNotificationRequest = bankingWebhookHandler.getTransferNotificationRequest();
286-
const genericWebhook = bankingWebhookHandler.getGenericWebhook();
287-
expect(accountHolderNotificationRequest.type).toEqual(AuthenticationNotificationRequest.TypeEnum.BalancePlatformAuthenticationCreated);
288-
expect(genericWebhook instanceof AccountHolderNotificationRequest).toBe(false);
289-
expect(genericWebhook instanceof AuthenticationNotificationRequest).toBe(true);
290-
});
291-
292244
it("should deserialize Management v3 Webhooks", function (): void {
293245
const json = {
294246
"type": "paymentMethodRequest.removed",
@@ -304,9 +256,9 @@ describe("Notification Test", function (): void {
304256
}
305257
};
306258
const jsonString = JSON.stringify(json);
307-
const managementWebhookHandler = new ManagementWebhookHandler(jsonString);
308-
const paymentMethodRequestRemoved: PaymentMethodRequestRemovedNotificationRequest = managementWebhookHandler.getPaymentMethodRequestRemovedNotificationRequest();
309-
const genericWebhook = managementWebhookHandler.getGenericWebhook();
259+
const managementWebhooksHandler = new ManagementWebhooksHandler(jsonString);
260+
const paymentMethodRequestRemoved: PaymentMethodRequestRemovedNotificationRequest = managementWebhooksHandler.getPaymentMethodRequestRemovedNotificationRequest();
261+
const genericWebhook = managementWebhooksHandler.getGenericWebhook();
310262
expect(genericWebhook instanceof PaymentMethodRequestRemovedNotificationRequest).toBe(true);
311263
expect(genericWebhook instanceof PaymentMethodScheduledForRemovalNotificationRequest).toBe(false);
312264
expect(paymentMethodRequestRemoved.type).toEqual(PaymentMethodRequestRemovedNotificationRequest.TypeEnum.PaymentMethodRequestRemoved);
@@ -354,44 +306,6 @@ describe("Notification Test", function (): void {
354306
expect(genericWebhook instanceof PaymentMethodScheduledForRemovalNotificationRequest).toBe(false);
355307
});
356308

357-
it("should deserialize NegativeBalanceCompensationWarning Webhook", function (): void {
358-
const json = {
359-
"data": {
360-
"balancePlatform": "YOUR_BALANCE_PLATFORM",
361-
"creationDate": "2024-07-02T02:01:08+02:00",
362-
"id": "BA00000000000000000001",
363-
"accountHolder": {
364-
"description": "Description for the account holder.",
365-
"reference": "YOUR_REFERENCE",
366-
"id": "AH00000000000000000001"
367-
},
368-
"amount": {
369-
"currency": "EUR",
370-
"value": -145050
371-
},
372-
"liableBalanceAccountId": "BA11111111111111111111",
373-
"negativeBalanceSince": "2024-10-19T00:33:13+02:00",
374-
"scheduledCompensationAt": "2024-12-01T01:00:00+01:00"
375-
},
376-
"environment": "test",
377-
"timestamp": "2024-10-22T00:00:00+02:00",
378-
"type": "balancePlatform.negativeBalanceCompensationWarning.scheduled"
379-
};
380-
const jsonString = JSON.stringify(json);
381-
const bankingWebhookHandler = new BankingWebhookHandler(jsonString);
382-
const negativeBalanceCompensationWarningNotificationRequest = bankingWebhookHandler.getNegativeBalanceCompensationWarningNotificationRequest();
383-
expect(negativeBalanceCompensationWarningNotificationRequest).toBeTruthy();
384-
expect(negativeBalanceCompensationWarningNotificationRequest.type).toBe(NegativeBalanceCompensationWarningNotificationRequest
385-
.TypeEnum.BalancePlatformNegativeBalanceCompensationWarningScheduled
386-
);
387-
expect(negativeBalanceCompensationWarningNotificationRequest.environment).toBe("test");
388-
expect(negativeBalanceCompensationWarningNotificationRequest.timestamp?.toISOString()).toBe(new Date("2024-10-22T00:00:00+02:00").toISOString());
389-
expect(negativeBalanceCompensationWarningNotificationRequest.data).toBeDefined();
390-
expect(negativeBalanceCompensationWarningNotificationRequest.data.balancePlatform).toBe("YOUR_BALANCE_PLATFORM");
391-
expect(negativeBalanceCompensationWarningNotificationRequest.data.id).toBe("BA00000000000000000001");
392-
expect(negativeBalanceCompensationWarningNotificationRequest.data.creationDate?.toISOString()).toBe(new Date("2024-07-02T02:01:08+02:00").toISOString());
393-
});
394-
395309
it("should deserialize AcsWebhook AuthenticationNotificationRequest", function (): void {
396310
const json = {
397311
"data": {
@@ -768,13 +682,20 @@ describe("Notification Test", function (): void {
768682
// test getNegativeBalanceCompensationWarningNotificationRequest
769683
const negativeBalanceCompensationWarningNotificationRequest: NegativeBalanceCompensationWarningNotificationRequest = negativeBalanceWarningWebhooksHandler.getNegativeBalanceCompensationWarningNotificationRequest();
770684
expect(negativeBalanceCompensationWarningNotificationRequest.type).toEqual(NegativeBalanceCompensationWarningNotificationRequest.TypeEnum.BalancePlatformNegativeBalanceCompensationWarningScheduled);
685+
expect(negativeBalanceCompensationWarningNotificationRequest.environment).toBe("test");
686+
expect(negativeBalanceCompensationWarningNotificationRequest.timestamp?.toISOString()).toBe(new Date("2024-10-22T00:00:00+02:00").toISOString());
687+
expect(negativeBalanceCompensationWarningNotificationRequest.data).toBeDefined();
688+
expect(negativeBalanceCompensationWarningNotificationRequest.data.balancePlatform).toBe("YOUR_BALANCE_PLATFORM");
689+
expect(negativeBalanceCompensationWarningNotificationRequest.data.id).toBe("BA00000000000000000001");
690+
expect(negativeBalanceCompensationWarningNotificationRequest.data.creationDate?.toISOString()).toBe(new Date("2024-10-22T00:00:00+02:00").toISOString());
771691
// test getGenericWebhook
772692
const genericWebhook = negativeBalanceWarningWebhooksHandler.getGenericWebhook();
773693
expect(genericWebhook instanceof NegativeBalanceCompensationWarningNotificationRequest).toBe(true);
774694
expect(genericWebhook.type).toEqual("balancePlatform.negativeBalanceCompensationWarning.scheduled");
775695
expect(genericWebhook.data.accountHolder?.reference).toEqual("YOUR_REFERENCE");
776696
expect(genericWebhook.data.accountHolder?.id).toEqual("AH00000000000000000001");
777-
expect(genericWebhook.data.negativeBalanceSince?.toISOString()).toEqual(new Date("2024-10-19T00:33:13+02:00").toISOString());
697+
expect(genericWebhook.data.negativeBalanceSince?.toISOString()).toEqual(new Date("2024-10-19T00:33:13+02:00").toISOString());
698+
778699
});
779700

780701
});

0 commit comments

Comments
 (0)