Skip to content

Commit c6b6722

Browse files
committed
Add oneOf tests
1 parent 1898340 commit c6b6722

File tree

3 files changed

+122
-2
lines changed

3 files changed

+122
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* ######
3+
* ######
4+
* ############ ####( ###### #####. ###### ############ ############
5+
* ############# #####( ###### #####. ###### ############# #############
6+
* ###### #####( ###### #####. ###### ##### ###### ##### ######
7+
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
8+
* ###### ###### #####( ###### #####. ###### ##### ##### ######
9+
* ############# ############# ############# ############# ##### ######
10+
* ############ ############ ############# ############ ##### ######
11+
* ######
12+
* #############
13+
* ############
14+
* Adyen NodeJS API Library
15+
* Copyright (c) 2020 Adyen B.V.
16+
* This file is open source and available under the MIT license.
17+
* See the LICENSE file for more info.
18+
*/
19+
20+
/* tslint:disable */
21+
export const payments3DS2NativeAction = JSON.stringify({
22+
"action":{
23+
"type":"threeDS2",
24+
"subtype": "fingerprint",
25+
"paymentData":"Ab02b4c0!BQABAgCuZFJrQOjSsl\/zt+...",
26+
"paymentMethodType":"scheme",
27+
"authorisationToken" : "Ab02b4c0!BQABAgAvrX03p...",
28+
"token":"eyJ0aHJlZURTTWV0aG9kTm90aWZpY..."
29+
},
30+
pspReference: "JLCMPCQ8HXSKGK82",
31+
resultCode:"IdentifyShopper",
32+
}, null, 2);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* ######
3+
* ######
4+
* ############ ####( ###### #####. ###### ############ ############
5+
* ############# #####( ###### #####. ###### ############# #############
6+
* ###### #####( ###### #####. ###### ##### ###### ##### ######
7+
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
8+
* ###### ###### #####( ###### #####. ###### ##### ##### ######
9+
* ############# ############# ############# ############# ##### ######
10+
* ############ ############ ############# ############ ##### ######
11+
* ######
12+
* #############
13+
* ############
14+
* Adyen NodeJS API Library
15+
* Copyright (c) 2020 Adyen B.V.
16+
* This file is open source and available under the MIT license.
17+
* See the LICENSE file for more info.
18+
*/
19+
20+
/* tslint:disable */
21+
export const paymentsRedirectAction = JSON.stringify({
22+
additionalData: {
23+
"cardSummary": "5454",
24+
"threeds2.threeDS2ResponseData.messageVersion": "2.1.0",
25+
"threeds2.threeDS2Token": "R5CZ2NWPJTGV9D82...",
26+
"threeds2.threeDSServerTransID": "8835538461311270...",
27+
"cardBin": "545454",
28+
"threeds2.cardEnrolled": "true",
29+
"paymentMethod": "mc",
30+
"cardPaymentMethod": "mc",
31+
"fundingSource": "CREDIT",
32+
"merchantReference": "Your order number",
33+
"issuerBin": "54545454",
34+
"threeds2.threeDSMethodURL": "https://pal-test.adyen.com/threeds2simulator/acs/startMethod.shtml",
35+
"cardIssuingCountry": "PL"
36+
},
37+
pspReference: "JLCMPCQ8HXSKGK82",
38+
resultCode: "RedirectShopper",
39+
action: {
40+
paymentMethodType: "scheme",
41+
url: "https://checkoutshopper-test.adyen.com/checkoutshopper/threeDS/redirect...",
42+
method: "GET",
43+
type: "redirect"
44+
}
45+
}, null, 2);

src/__tests__/checkout.spec.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import nock from "nock";
22
import {createClient} from "../__mocks__/base";
33
import {paymentMethodsSuccess} from "../__mocks__/checkout/paymentMethodsSuccess";
44
import {paymentsSuccess} from "../__mocks__/checkout/paymentsSuccess";
5+
import {paymentsRedirectAction} from "../__mocks__/checkout/paymentsRedirectAction";
56
import {paymentDetailsSuccess} from "../__mocks__/checkout/paymentsDetailsSuccess";
7+
import {PaymentResponseActionClass} from "../typings/checkout/paymentResponseAction";
68
// import {paymentSessionSuccess} from "../__mocks__/checkout/paymentSessionSucess";
79
import {originKeysSuccess} from "../__mocks__/checkout/originkeysSuccess";
810
import {paymentsResultMultibancoSuccess} from "../__mocks__/checkout/paymentsResultMultibancoSuccess";
@@ -14,6 +16,8 @@ import HttpClientException from "../httpClient/httpClientException";
1416
import { checkout } from "../typings";
1517
import { IRequest } from "../typings/requestOptions";
1618
import { SessionResultResponse } from "../typings/checkout/sessionResultResponse";
19+
import { payments3DS2NativeAction } from "../__mocks__/checkout/payments3DS2NativeAction";
20+
import { CheckoutThreeDS2Action } from "../typings/checkout/checkoutThreeDS2Action";
1721

1822
const merchantAccount = process.env.ADYEN_MERCHANT!;
1923
const reference = "Your order number";
@@ -154,7 +158,7 @@ describe("Checkout", (): void => {
154158
"returnUrl": "https://your-company.com/...",
155159
"merchantAccount": "YOUR_MERCHANT_ACCOUNT"
156160
}`);
157-
const paymentRequest: checkout.PaymentRequest = await checkout.ObjectSerializer.deserialize(requestJson,"PaymentRequest");
161+
const paymentRequest: checkout.PaymentRequest = await checkout.ObjectSerializer.deserialize(requestJson, "PaymentRequest", "");
158162
expect(paymentRequest.returnUrl).toEqual("https://your-company.com/...");
159163
expect(paymentRequest.amount.value).toBe(1000);
160164
const paymentMethodDetails: checkout.ApplePayDetails = paymentRequest.paymentMethod as checkout.ApplePayDetails;
@@ -239,7 +243,6 @@ describe("Checkout", (): void => {
239243

240244
});
241245

242-
243246
test("should make a payment.", async (): Promise<void> => {
244247
scope.post("/payments")
245248
.reply(200, paymentsSuccess);
@@ -401,6 +404,46 @@ describe("Checkout", (): void => {
401404
expect(paymentsResponse.additionalData).toBeTruthy();
402405
});
403406

407+
test("should return shopper redirect with a card payment.", async (): Promise<void> => {
408+
scope.post("/payments")
409+
.reply(200, paymentsRedirectAction);
410+
411+
const paymentsRequest: checkout.PaymentRequest = createPaymentsCheckoutRequest();
412+
const paymentsResponse: checkout.PaymentResponse = await checkoutService.PaymentsApi.payments(paymentsRequest);
413+
414+
expect(paymentsResponse.pspReference).toBeTruthy();
415+
expect(paymentsResponse.resultCode).toBeTruthy();
416+
expect(paymentsResponse.resultCode).toEqual("RedirectShopper");
417+
// check action is polymorphic
418+
expect(paymentsResponse.action).toBeTruthy();
419+
expect(paymentsResponse.action).toBeInstanceOf(PaymentResponseActionClass);
420+
// check is redirect
421+
expect(paymentsResponse.action?.type).toBeTruthy();
422+
expect(paymentsResponse.action?.type).toEqual("redirect");
423+
expect(paymentsResponse.action?.url).toBe("https://checkoutshopper-test.adyen.com/checkoutshopper/threeDS/redirect...");
424+
425+
});
426+
427+
test.only("should return Native 3DS2 with a card payment.", async (): Promise<void> => {
428+
scope.post("/payments")
429+
.reply(200, payments3DS2NativeAction);
430+
431+
const paymentsRequest: checkout.PaymentRequest = createPaymentsCheckoutRequest();
432+
const paymentsResponse: checkout.PaymentResponse = await checkoutService.PaymentsApi.payments(paymentsRequest);
433+
434+
expect(paymentsResponse.pspReference).toBeTruthy();
435+
expect(paymentsResponse.resultCode).toBeTruthy();
436+
expect(paymentsResponse.resultCode).toEqual("IdentifyShopper");
437+
// check action is polymorphic
438+
expect(paymentsResponse.action).toBeTruthy();
439+
expect(paymentsResponse.action).toBeInstanceOf(CheckoutThreeDS2Action);
440+
// check is threeDS2
441+
expect(paymentsResponse.action?.type).toBeTruthy();
442+
expect(paymentsResponse.action?.type).toEqual("threeDS2");
443+
expect(paymentsResponse.action?.subtype).toEqual("threeDS2");
444+
445+
});
446+
404447
test("should get origin keys", async (): Promise<void> => {
405448
const checkoutUtility = new CheckoutAPI(client);
406449
const originKeysRequest: checkout.UtilityRequest = {

0 commit comments

Comments
 (0)