Skip to content

Add unit tests for parsing unexpected fields/enums #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/__mocks__/legalEntityManagement/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,47 @@ export const legalEntity = {
"type": "individual"
};

export const legalEntityAdditionalAttributes = {
"id": "123456789",
"additionalAttribute": "something",
"individual": {
"email": "string",
"name": {
"firstName": "string",
"infix": "string",
"lastName": "string"
},
"nationality": "string",
"phone": {
"number": "string",
"type": "string"
},
},
"reference": "string",
"transferInstruments": [{ "id": "string" }],
"type": "individual"
};

export const legalEntityUnknownEnum = {
"id": "123456789",
"individual": {
"email": "string",
"name": {
"firstName": "string",
"infix": "string",
"lastName": "string"
},
"nationality": "string",
"phone": {
"number": "string",
"type": "string"
},
},
"reference": "string",
"transferInstruments": [{ "id": "string" }],
"type": "this is unknown"
};

export const businessLines = {
"businessLines": [{
"capability": "receivePayments",
Expand Down
40 changes: 40 additions & 0 deletions src/__mocks__/terminalApi/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,43 @@ export const syncResEventNotification = {
}
}
};

export const syncResEventNotificationWithAdditionalAttributes = {
"SaleToPOIRequest":{
"EventNotification":{
"EventDetails":"newstate=IDLE&oldstate=START",
"EventToNotify":"Shutdown",
"TimeStamp":"2019-08-07T10:16:10.000Z",
"AdditionalAttribute": "Something"
},
"MessageHeader":{
"SaleID":"POSSystemID12345",
"ProtocolVersion":"3.0",
"MessageType":"Notification",
"POIID":"V400m-324688179",
"MessageClass":"Event",
"MessageCategory":"Event",
"DeviceID":"1517998561",
"AdditionalAttribute": "SomethingElse"
}
}
};

export const syncResEventNotificationWithUnknownEnum = {
"SaleToPOIRequest":{
"EventNotification":{
"EventDetails":"newstate=IDLE&oldstate=START",
"EventToNotify":"This is unknown",
"TimeStamp":"2019-08-07T10:16:10.000Z"
},
"MessageHeader":{
"SaleID":"POSSystemID12345",
"ProtocolVersion":"3.0",
"MessageType":"Notification",
"POIID":"V400m-324688179",
"MessageClass":"Event",
"MessageCategory":"Event",
"DeviceID":"1517998561"
}
}
};
26 changes: 0 additions & 26 deletions src/__tests__/checkout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ export function createPaymentsCheckoutRequest(): checkout.PaymentRequest {
};
}

// function createPaymentSessionRequest(): checkout.PaymentSetupRequest {
// return {
// amount: createAmountObject("USD", 1000),
// countryCode: "NL",
// merchantAccount,
// reference,
// returnUrl: "https://your-company.com/...",
// channel: checkout.PaymentSetupRequest.ChannelEnum.Web,
// sdkVersion: "3.7.0"
// };
// }

function createUpdatePaymentLinkRequest(): checkout.UpdatePaymentLinkRequest {
return {
"status": checkout.UpdatePaymentLinkRequest.StatusEnum.Expired
Expand Down Expand Up @@ -203,20 +191,6 @@ describe("Checkout", (): void => {
.matchHeader("Idempotency-Key", "testKey");
await checkoutService.PaymentsApi.paymentsDetails(createPaymentsDetailsRequest(), {idempotencyKey: "testKey"});

// scope.post("/paymentSession")
// .reply(200, paymentSessionSuccess)
// .matchHeader("Idempotency-Key", "testKey");
// const paymentSessionRequest: checkout.PaymentSetupRequest = createPaymentSessionRequest();
// await checkoutService.ClassicCheckoutSDKApi.paymentSession(paymentSessionRequest, {idempotencyKey: "testKey"});

// scope.post("/payments/result")
// .reply(200, paymentsResultSuccess)
// .matchHeader("Idempotency-Key", "testKey");
// const paymentResultRequest: checkout.PaymentVerificationRequest = {
// payload: "This is a test payload",
// };
// await checkoutService.ClassicCheckoutSDKApi.verifyPaymentResult(paymentResultRequest, {idempotencyKey: "testKey"});

const orderRequest: checkout.CreateOrderRequest = {
amount: createAmountObject("USD", 1000),
merchantAccount,
Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/legalEntityManagement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
businessLines,
document,
legalEntity,
legalEntityAdditionalAttributes,
legalEntityUnknownEnum,
onboardingLink,
onboardingTheme,
onboardingThemes,
Expand Down Expand Up @@ -69,6 +71,29 @@ describe("Legal Entity Management", (): void => {
expect(response.type).toBe("individual");
});

it("should support GET /legalEntities/{id} with additional attributes", async (): Promise<void> => {
scope.get(`/legalEntities/${id}`)
.reply(200, legalEntityAdditionalAttributes);

await expect(async () => {
const response = await legalEntityManagement.LegalEntitiesApi.getLegalEntity("123456789");
expect(response.id).toBe(id);
expect(response.type).toBe("individual");
}).not.toThrow();
});

it("should support GET /legalEntities/{id} with unknown enum", async (): Promise<void> => {
scope.get(`/legalEntities/${id}`)
.reply(200, legalEntityUnknownEnum);

await expect(async () => {
const response = await legalEntityManagement.LegalEntitiesApi.getLegalEntity("123456789");
expect(response.id).toBe(id);
// type is unknown, so it should not be defined
expect(response.type).toBeUndefined;
}).not.toThrow();
});

it("should support PATCH /legalEntities/{id}", async (): Promise<void> => {
scope.patch(`/legalEntities/${id}`)
.reply(200, legalEntity);
Expand Down
Loading