Skip to content

Commit 1e9277b

Browse files
committed
Add Tokenization Webhooks tests
1 parent 0a76a82 commit 1e9277b

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { TokenizationAlreadyExistingDetailsNotificationRequest } from "../../typings/tokenizationWebhooks/tokenizationAlreadyExistingDetailsNotificationRequest";
2+
import { TokenizationCreatedDetailsNotificationRequest } from "../../typings/tokenizationWebhooks/tokenizationCreatedDetailsNotificationRequest";
3+
import { TokenizationDisabledDetailsNotificationRequest } from "../../typings/tokenizationWebhooks/tokenizationDisabledDetailsNotificationRequest";
4+
import { TokenizationUpdatedDetailsNotificationRequest } from "../../typings/tokenizationWebhooks/tokenizationUpdatedDetailsNotificationRequest";
5+
import { TokenizationWebhooksHandler } from "../../typings/tokenizationWebhooks/tokenizationWebhooksHandler";
6+
7+
describe("TokenizationWebhooksHandler", () => {
8+
it("should deserialize TokenizationAlreadyExistingDetailsNotificationRequest", () => {
9+
const json = {
10+
"createdAt": "2025-06-30T16:40:23+02:00",
11+
"eventId": "QBQQ9DLNRHHKGK38",
12+
"environment": "test",
13+
"data": {
14+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
15+
"storedPaymentMethodId": "M5N7TQ4TG5PFWR50",
16+
"type": "visastandarddebit",
17+
"operation": "alreadyExisting",
18+
"shopperReference": "YOUR_SHOPPER_REFERENCE"
19+
},
20+
"type": "recurring.token.alreadyExisting"
21+
};
22+
const handler = new TokenizationWebhooksHandler(JSON.stringify(json));
23+
const request = handler.getTokenizationAlreadyExistingDetailsNotificationRequest();
24+
expect(request).toBeTruthy();
25+
expect(request.type).toBe(TokenizationAlreadyExistingDetailsNotificationRequest.TypeEnum.RecurringTokenAlreadyExisting);
26+
expect(request.data.type).toBe("visastandarddebit");
27+
// test GenericWebhook
28+
const genericWebhook = handler.getGenericWebhook();
29+
expect(genericWebhook).toBeInstanceOf(TokenizationAlreadyExistingDetailsNotificationRequest);
30+
expect(genericWebhook.type).toBe("recurring.token.alreadyExisting");
31+
});
32+
33+
it("should deserialize TokenizationCreatedDetailsNotificationRequest", () => {
34+
const json = {
35+
"createdAt": "2025-06-30T16:40:23+02:00",
36+
"eventId": "QBQQ9DLNRHHKGK38",
37+
"environment": "test",
38+
"data": {
39+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
40+
"storedPaymentMethodId": "M5N7TQ4TG5PFWR50",
41+
"type": "visastandarddebit",
42+
"operation": "created",
43+
"shopperReference": "YOUR_SHOPPER_REFERENCE"
44+
},
45+
"type": "recurring.token.created"
46+
};
47+
const handler = new TokenizationWebhooksHandler(JSON.stringify(json));
48+
const request = handler.getTokenizationCreatedDetailsNotificationRequest();
49+
expect(request).toBeTruthy();
50+
expect(request.type).toBe(TokenizationCreatedDetailsNotificationRequest.TypeEnum.RecurringTokenCreated);
51+
expect(request.data.type).toBe("visastandarddebit");
52+
// test GenericWebhook
53+
const genericWebhook = handler.getGenericWebhook();
54+
expect(genericWebhook).toBeInstanceOf(TokenizationCreatedDetailsNotificationRequest);
55+
expect(genericWebhook.type).toBe("recurring.token.created");
56+
});
57+
58+
it("should deserialize TokenizationUpdatedDetailsNotificationRequest", () => {
59+
const json = {
60+
"createdAt": "2025-06-30T16:40:23+02:00",
61+
"eventId": "QBQQ9DLNRHHKGK38",
62+
"environment": "test",
63+
"data": {
64+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
65+
"storedPaymentMethodId": "M5N7TQ4TG5PFWR50",
66+
"type": "visastandarddebit",
67+
"operation": "updated",
68+
"shopperReference": "YOUR_SHOPPER_REFERENCE"
69+
},
70+
"type": "recurring.token.updated"
71+
};
72+
const handler = new TokenizationWebhooksHandler(JSON.stringify(json));
73+
const request = handler.getTokenizationUpdatedDetailsNotificationRequest();
74+
expect(request).toBeTruthy();
75+
expect(request.type).toBe(TokenizationUpdatedDetailsNotificationRequest.TypeEnum.RecurringTokenUpdated);
76+
expect(request.data.type).toBe("visastandarddebit");
77+
// test GenericWebhook
78+
const genericWebhook = handler.getGenericWebhook();
79+
expect(genericWebhook).toBeInstanceOf(TokenizationUpdatedDetailsNotificationRequest);
80+
expect(genericWebhook.type).toBe("recurring.token.updated");
81+
});
82+
83+
it("should deserialize TokenizationDisabledDetailsNotificationRequest", () => {
84+
const json = {
85+
"createdAt": "2025-06-30T16:40:23+02:00",
86+
"eventId": "QBQQ9DLNRHHKGK38",
87+
"environment": "test",
88+
"data": {
89+
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
90+
"storedPaymentMethodId": "M5N7TQ4TG5PFWR50",
91+
"type": "visastandarddebit",
92+
"shopperReference": "YOUR_SHOPPER_REFERENCE"
93+
},
94+
"type": "recurring.token.disabled"
95+
};
96+
const handler = new TokenizationWebhooksHandler(JSON.stringify(json));
97+
const request = handler.getTokenizationDisabledDetailsNotificationRequest();
98+
expect(request).toBeTruthy();
99+
expect(request.type).toBe(TokenizationDisabledDetailsNotificationRequest.TypeEnum.RecurringTokenDisabled);
100+
expect(request.data.type).toBe("visastandarddebit");
101+
// test GenericWebhook
102+
const genericWebhook = handler.getGenericWebhook();
103+
expect(genericWebhook).toBeInstanceOf(TokenizationDisabledDetailsNotificationRequest);
104+
expect(genericWebhook.type).toBe("recurring.token.disabled");
105+
});
106+
107+
it("should throw error for unknown type", () => {
108+
const json = {
109+
type: "unknown.type",
110+
data: {}
111+
};
112+
const handler = new TokenizationWebhooksHandler(JSON.stringify(json));
113+
expect(() => handler.getGenericWebhook()).toThrow("Could not parse the json payload");
114+
});
115+
116+
it("should throw SyntaxError for invalid JSON", () => {
117+
expect(() => new TokenizationWebhooksHandler("{ invalid json }")).toThrow(SyntaxError);
118+
});
119+
});

0 commit comments

Comments
 (0)