Skip to content

Commit 1d6b9b7

Browse files
authored
Merge pull request #1518 from Adyen/tests-unknown-enums
Add unit tests for parsing unexpected fields/enums
2 parents 4bbf90f + 34a63c9 commit 1d6b9b7

File tree

7 files changed

+535
-30
lines changed

7 files changed

+535
-30
lines changed

.github/workflows/node-ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ jobs:
5959
${{ runner.os }}-node-
6060
- name: Install dependencies
6161
run: npm install
62-
- name: Run tests
63-
run: npm test
6462
- name: Run tests with coverage
6563
run: npm run test:coverage
6664

src/__mocks__/legalEntityManagement/responses.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,47 @@ export const legalEntity = {
193193
"type": "individual"
194194
};
195195

196+
export const legalEntityAdditionalAttributes = {
197+
"id": "123456789",
198+
"additionalAttribute": "something",
199+
"individual": {
200+
"email": "string",
201+
"name": {
202+
"firstName": "string",
203+
"infix": "string",
204+
"lastName": "string"
205+
},
206+
"nationality": "string",
207+
"phone": {
208+
"number": "string",
209+
"type": "string"
210+
},
211+
},
212+
"reference": "string",
213+
"transferInstruments": [{ "id": "string" }],
214+
"type": "individual"
215+
};
216+
217+
export const legalEntityUnknownEnum = {
218+
"id": "123456789",
219+
"individual": {
220+
"email": "string",
221+
"name": {
222+
"firstName": "string",
223+
"infix": "string",
224+
"lastName": "string"
225+
},
226+
"nationality": "string",
227+
"phone": {
228+
"number": "string",
229+
"type": "string"
230+
},
231+
},
232+
"reference": "string",
233+
"transferInstruments": [{ "id": "string" }],
234+
"type": "this is unknown"
235+
};
236+
196237
export const businessLines = {
197238
"businessLines": [{
198239
"capability": "receivePayments",

src/__mocks__/terminalApi/sync.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,43 @@ export const syncResEventNotification = {
386386
}
387387
}
388388
};
389+
390+
export const syncResEventNotificationWithAdditionalAttributes = {
391+
"SaleToPOIRequest":{
392+
"EventNotification":{
393+
"EventDetails":"newstate=IDLE&oldstate=START",
394+
"EventToNotify":"Shutdown",
395+
"TimeStamp":"2019-08-07T10:16:10.000Z",
396+
"AdditionalAttribute": "Something"
397+
},
398+
"MessageHeader":{
399+
"SaleID":"POSSystemID12345",
400+
"ProtocolVersion":"3.0",
401+
"MessageType":"Notification",
402+
"POIID":"V400m-324688179",
403+
"MessageClass":"Event",
404+
"MessageCategory":"Event",
405+
"DeviceID":"1517998561",
406+
"AdditionalAttribute": "SomethingElse"
407+
}
408+
}
409+
};
410+
411+
export const syncResEventNotificationWithUnknownEnum = {
412+
"SaleToPOIRequest":{
413+
"EventNotification":{
414+
"EventDetails":"newstate=IDLE&oldstate=START",
415+
"EventToNotify":"this is unknown",
416+
"TimeStamp":"2019-08-07T10:16:10.000Z"
417+
},
418+
"MessageHeader":{
419+
"SaleID":"POSSystemID12345",
420+
"ProtocolVersion":"3.0",
421+
"MessageType":"Notification",
422+
"POIID":"V400m-324688179",
423+
"MessageClass":"Event",
424+
"MessageCategory":"Event",
425+
"DeviceID":"1517998561"
426+
}
427+
}
428+
};

src/__tests__/checkout.spec.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,6 @@ export function createPaymentsCheckoutRequest(): checkout.PaymentRequest {
5656
};
5757
}
5858

59-
// function createPaymentSessionRequest(): checkout.PaymentSetupRequest {
60-
// return {
61-
// amount: createAmountObject("USD", 1000),
62-
// countryCode: "NL",
63-
// merchantAccount,
64-
// reference,
65-
// returnUrl: "https://your-company.com/...",
66-
// channel: checkout.PaymentSetupRequest.ChannelEnum.Web,
67-
// sdkVersion: "3.7.0"
68-
// };
69-
// }
70-
7159
function createUpdatePaymentLinkRequest(): checkout.UpdatePaymentLinkRequest {
7260
return {
7361
"status": checkout.UpdatePaymentLinkRequest.StatusEnum.Expired
@@ -203,20 +191,6 @@ describe("Checkout", (): void => {
203191
.matchHeader("Idempotency-Key", "testKey");
204192
await checkoutService.PaymentsApi.paymentsDetails(createPaymentsDetailsRequest(), {idempotencyKey: "testKey"});
205193

206-
// scope.post("/paymentSession")
207-
// .reply(200, paymentSessionSuccess)
208-
// .matchHeader("Idempotency-Key", "testKey");
209-
// const paymentSessionRequest: checkout.PaymentSetupRequest = createPaymentSessionRequest();
210-
// await checkoutService.ClassicCheckoutSDKApi.paymentSession(paymentSessionRequest, {idempotencyKey: "testKey"});
211-
212-
// scope.post("/payments/result")
213-
// .reply(200, paymentsResultSuccess)
214-
// .matchHeader("Idempotency-Key", "testKey");
215-
// const paymentResultRequest: checkout.PaymentVerificationRequest = {
216-
// payload: "This is a test payload",
217-
// };
218-
// await checkoutService.ClassicCheckoutSDKApi.verifyPaymentResult(paymentResultRequest, {idempotencyKey: "testKey"});
219-
220194
const orderRequest: checkout.CreateOrderRequest = {
221195
amount: createAmountObject("USD", 1000),
222196
merchantAccount,

src/__tests__/legalEntityManagement.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
businessLines,
1414
document,
1515
legalEntity,
16+
legalEntityAdditionalAttributes,
17+
legalEntityUnknownEnum,
1618
onboardingLink,
1719
onboardingTheme,
1820
onboardingThemes,
@@ -69,6 +71,29 @@ describe("Legal Entity Management", (): void => {
6971
expect(response.type).toBe("individual");
7072
});
7173

74+
it("should support GET /legalEntities/{id} with additional attributes", async (): Promise<void> => {
75+
scope.get(`/legalEntities/${id}`)
76+
.reply(200, legalEntityAdditionalAttributes);
77+
78+
await expect(async () => {
79+
const response = await legalEntityManagement.LegalEntitiesApi.getLegalEntity("123456789");
80+
expect(response.id).toBe(id);
81+
expect(response.type).toBe("individual");
82+
}).not.toThrow();
83+
});
84+
85+
it("should support GET /legalEntities/{id} with unknown enum", async (): Promise<void> => {
86+
scope.get(`/legalEntities/${id}`)
87+
.reply(200, legalEntityUnknownEnum);
88+
89+
await expect(async () => {
90+
const response = await legalEntityManagement.LegalEntitiesApi.getLegalEntity("123456789");
91+
expect(response.id).toBe(id);
92+
// type is unknown, so it holds whatever value is found in the payload
93+
expect(response.type).toBe("this is unknown");
94+
}).not.toThrow();
95+
});
96+
7297
it("should support PATCH /legalEntities/{id}", async (): Promise<void> => {
7398
scope.patch(`/legalEntities/${id}`)
7499
.reply(200, legalEntity);

0 commit comments

Comments
 (0)