Skip to content

Commit 93c6406

Browse files
committed
Generate and test DisputeWebhooks
1 parent 54685d8 commit 93c6406

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

src/__tests__/webhooks/bankingWebhooks.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import { NegativeBalanceWarningWebhooksHandler } from "../../typings/negativeBal
1717
import { TransactionWebhooksHandler } from "../../typings/transactionWebhooks/transactionWebhooksHandler";
1818
import { BalanceWebhooksHandler } from "../../typings/balanceWebhooks/balanceWebhooksHandler";
1919
import { ReportNotificationRequest } from "../../typings/reportWebhooks/reportNotificationRequest";
20+
import { DisputeWebhooksHandler } from "../../typings/disputeWebhooks/disputeWebhooksHandler";
21+
import { DisputeNotificationRequest } from "../../typings/disputeWebhooks/disputeNotificationRequest";
22+
import { DisputeEventNotification } from "../../typings/disputeWebhooks/disputeEventNotification";
2023

2124
describe("BankingWebhooks Tests", function (): void {
2225

@@ -514,4 +517,36 @@ describe("BankingWebhooks Tests", function (): void {
514517

515518
});
516519

520+
it("should deserialize DisputeWebhooks DisputeNotificationRequest", function (): void {
521+
const json = {
522+
"type": "balancePlatform.dispute.created",
523+
"data": {
524+
"id": "DS00000000000000000001",
525+
"balancePlatform": "YOUR_BALANCE_PLATFORM",
526+
"disputedAmount": {
527+
"currency": "EUR",
528+
"value": 10000
529+
},
530+
"status": "open",
531+
"type": DisputeEventNotification.TypeEnum.NotDelivered,
532+
533+
}
534+
};
535+
const jsonString = JSON.stringify(json);
536+
const disputeWebhooksHandler = new DisputeWebhooksHandler(jsonString);
537+
const disputeNotificationRequest: DisputeNotificationRequest = disputeWebhooksHandler.getDisputeNotificationRequest();
538+
539+
expect(disputeNotificationRequest).toBeTruthy();
540+
expect(disputeNotificationRequest.type).toBe("balancePlatform.dispute.created");
541+
expect(disputeNotificationRequest.data).toBeDefined();
542+
expect(disputeNotificationRequest.data.id).toBe("DS00000000000000000001");
543+
expect(disputeNotificationRequest.data.balancePlatform).toBe("YOUR_BALANCE_PLATFORM");
544+
expect(disputeNotificationRequest.data.status).toBe("open");
545+
expect(disputeNotificationRequest.data.type).toBe(DisputeEventNotification.TypeEnum.NotDelivered);
546+
// test getGenericWebhook
547+
const genericWebhook = disputeWebhooksHandler.getGenericWebhook();
548+
expect(genericWebhook instanceof DisputeNotificationRequest).toBe(true);
549+
expect(genericWebhook.type).toEqual("balancePlatform.dispute.created");
550+
});
551+
517552
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* The version of the OpenAPI document: v1
3+
*
4+
*
5+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
6+
* https://openapi-generator.tech
7+
* Do not edit this class manually.
8+
*/
9+
10+
import { disputeWebhooks } from "..";
11+
12+
/**
13+
* Union type for all supported webhook requests.
14+
* Allows generic handling of configuration-related webhook events.
15+
*/
16+
export type GenericWebhook =
17+
| disputeWebhooks.DisputeNotificationRequest;
18+
19+
/**
20+
* Handler for processing DisputeWebhooks.
21+
*
22+
* This class provides functionality to deserialize the payload of DisputeWebhooks events.
23+
*/
24+
export class DisputeWebhooksHandler {
25+
26+
private readonly payload: Record<string, any>;
27+
28+
public constructor(jsonPayload: string) {
29+
this.payload = JSON.parse(jsonPayload);
30+
}
31+
32+
/**
33+
* This method checks the type of the webhook payload and returns the appropriate deserialized object.
34+
*
35+
* @returns A deserialized object of type GenericWebhook.
36+
* @throws Error if the type is not recognized.
37+
*/
38+
public getGenericWebhook(): GenericWebhook {
39+
40+
const type = this.payload["type"];
41+
42+
if(Object.values(disputeWebhooks.DisputeNotificationRequest.TypeEnum).includes(type)) {
43+
return this.getDisputeNotificationRequest();
44+
}
45+
46+
throw new Error("Could not parse the json payload: " + this.payload);
47+
48+
}
49+
50+
/**
51+
* Deserialize the webhook payload into a DisputeNotificationRequest
52+
*
53+
* @returns Deserialized DisputeNotificationRequest object.
54+
*/
55+
public getDisputeNotificationRequest(): disputeWebhooks.DisputeNotificationRequest {
56+
return disputeWebhooks.ObjectSerializer.deserialize(this.payload, "DisputeNotificationRequest");
57+
}
58+
59+
}

src/typings/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ export * as managementWebhooks from "./managementWebhooks/models";
3434
export * as acsWebhooks from "./acsWebhooks/models";
3535
export * as transactionWebhooks from "./transactionWebhooks/models";
3636
export * as negativeBalanceWarningWebhooks from "./negativeBalanceWarningWebhooks/models";
37-
export * as balanceWebhooks from "./balanceWebhooks/models";
37+
export * as balanceWebhooks from "./balanceWebhooks/models";
38+
export * as disputeWebhooks from "./disputeWebhooks/models";

0 commit comments

Comments
 (0)