Skip to content

Commit 31b4a9d

Browse files
committed
Add test for forward endpoint
1 parent 41e5726 commit 31b4a9d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"pspReference": "PSP123456789",
3+
"response": {
4+
"body": "{\"data\": {\"tokenizeCreditCard\": {\"paymentMethod\": {\"id\": \"PAYMENT_METHOD_ID\"}}}}",
5+
"headers": {
6+
"Content-Type": "application/json"
7+
},
8+
"status": 200
9+
},
10+
"storedPaymentMethodId": "PAYMENT_METHOD_ID"
11+
}

src/__tests__/checkout.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { SessionResultResponse } from "../typings/checkout/sessionResultResponse
1515
import { payments3DS2NativeAction } from "../__mocks__/checkout/payments3DS2NativeAction";
1616
import { EnvironmentEnum } from "../config";
1717
import { Types } from "..";
18+
import forwardResponse from "../__mocks__/checkout/forwardResponse.json";
1819

1920
const merchantAccount = process.env.ADYEN_MERCHANT!;
2021
const reference = "Your order number";
@@ -683,4 +684,48 @@ describe("Checkout", (): void => {
683684
expect(resultOfPaymentSessionResponse.id).toEqual("CS12345678");
684685
expect(resultOfPaymentSessionResponse.status).toEqual(SessionResultResponse.StatusEnum.Completed);
685686
});
687+
688+
test("Should forward token", async (): Promise<void> => {
689+
scope.post("/forward")
690+
.reply(200, forwardResponse);
691+
692+
const body = {
693+
amount: {
694+
value: 100,
695+
currency: "USD"
696+
},
697+
paymentMethod: {
698+
creditCard: {
699+
holderName: "{{holderName}}",
700+
number: "{{number}}",
701+
expiryMonth: "{{expiryMonth}}",
702+
expiryYear: "{{expiryYear}}"
703+
}
704+
}
705+
};
706+
707+
const checkoutForwardRequest: Types.checkout.CheckoutForwardRequest = {
708+
merchantAccount: "YOUR_MERCHANT_ACCOUNT",
709+
shopperReference: "YOUR_SHOPPER_REFERENCE",
710+
storedPaymentMethodId: "M12345677890",
711+
baseUrl: "http://thirdparty.example.com",
712+
request: {
713+
httpMethod: Types.checkout.CheckoutOutgoingForwardRequest.HttpMethodEnum.Post,
714+
urlSuffix: "/payments",
715+
credentials: "YOUR_CREDENTIALS_FOR_THE_THIRD_PARTY",
716+
headers: {
717+
"Authorization": "Basic {{credentials}}",
718+
},
719+
body: JSON.stringify(body),
720+
}
721+
};
722+
723+
const response: Types.checkout.CheckoutForwardResponse = await checkoutService.RecurringApi.forward(checkoutForwardRequest);
724+
725+
expect(response.pspReference).toEqual("PSP123456789");
726+
expect(response.storedPaymentMethodId).toEqual("PAYMENT_METHOD_ID");
727+
expect(response.response).toBeDefined();
728+
expect(response.response.status).toEqual(200);
729+
expect(response.response.body).toContain("PAYMENT_METHOD_ID");
730+
});
686731
});

0 commit comments

Comments
 (0)