Skip to content

Commit

Permalink
Merge pull request #102 from mediaopt/feature/36076-apple-pay
Browse files Browse the repository at this point in the history
Feature/36076 apple pay
  • Loading branch information
majidabbasimediaopt authored Apr 22, 2024
2 parents 4480807 + 67c61e1 commit a8eed53
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paypal-commercetools-client",
"version": "0.1.29-alpha",
"version": "0.1.30-alpha",
"private": false,
"type": "module",
"license": "MIT",
Expand Down
2 changes: 0 additions & 2 deletions src/app/usePayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ export const PaymentProvider: FC<
!!setRatepayMessage,
enableVaulting
);
console.log(relevantOrderData);
const createOrderResult = await createOrder(
requestHeader,
createOrderUrl,
Expand All @@ -220,7 +219,6 @@ export const PaymentProvider: FC<
...relevantOrderData,
}
);
console.log(createOrderResult);
const oldOrderData = orderData;

if (createOrderResult) {
Expand Down
9 changes: 9 additions & 0 deletions src/components/ApplePay/ApplePay.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { render, screen } from "@testing-library/react";
import { ApplePay } from "./ApplePay";

import { applePayTestParams } from "./constants";

test("ApplePay is shown", () => {
render(<ApplePay {...applePayTestParams} />);
expect(screen).toBeDefined();
});
26 changes: 26 additions & 0 deletions src/components/ApplePay/ApplePayButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render, screen } from "@testing-library/react";
import { ApplePayButton } from "./ApplePayButton";

import { applePayTestParams } from "./constants";

jest.mock("./ApplePayMask", () => ({
ApplePayMask: () => <div>ApplePayMask</div>,
}));
jest.mock("../../app/usePayment", () => ({
usePayment: () => {
return { paymentInfo: { id: "123" } };
},
}));
jest.mock("../../app/useHandleCreatePayment", () => ({
useHandleCreatePayment: () => {
return {};
},
}));

test("ApplePayButton is shown", () => {
render(<ApplePayButton {...applePayTestParams} />);
expect(screen).toBeDefined();

const applePayMask = screen.getByText("ApplePayMask");
expect(applePayMask).toBeDefined();
});
18 changes: 18 additions & 0 deletions src/components/ApplePay/ApplePayMask.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { render, screen, waitFor } from "@testing-library/react";
import { ApplePayMask } from "./ApplePayMask";

import { applePayTestParams, DEVICE_ERROR } from "./constants";

jest.mock("../../app/loadScript", () => ({
__esModule: true,
default: () => Promise.resolve(),
}));

test("ApplePayMask is shown", async () => {
render(<ApplePayMask {...applePayTestParams} />);
await waitFor(() => {
expect(screen).toBeDefined();

expect(screen.getByText(DEVICE_ERROR)).toBeDefined();
});
});
3 changes: 2 additions & 1 deletion src/components/ApplePay/ApplePayMask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import loadScript from "../../app/loadScript";
import { usePayment } from "../../app/usePayment";
import { ERROR_TEXT_STYLE } from "../../styles";
import { useLoader } from "../../app/useLoader";
import { DEVICE_ERROR } from "./constants";
import {
CustomPayPalButtonsComponentProps,
ApplePayProps,
Expand Down Expand Up @@ -57,7 +58,7 @@ export const ApplePayMask: React.FC<ApplePayMaskComponentProps> = (props) => {
async () => {
const applePaySession: ApplePaySession = window.ApplePaySession;
if (!applePaySession) {
setError("This device does not support Apple Pay");
setError(DEVICE_ERROR);
return;
}
if (!applePaySession.canMakePayments()) {
Expand Down
19 changes: 19 additions & 0 deletions src/components/ApplePay/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
testParams,
testRequestHeader,
testOptions,
testVaultParams,
} from "../../constants";

export const applePayTestParams = {
...testParams,
requestHeader: testRequestHeader,
options: {
...testOptions,
components: "applepay,buttons",
buyerCountry: "US",
},
...testVaultParams,
applePayDisplayName: "My Store",
};
export const DEVICE_ERROR = "This device does not support Apple Pay";
2 changes: 0 additions & 2 deletions src/components/PaymentTokens/PaymentTokensList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { useSettings } from "../../app/useSettings";
export const PaymentTokensList: React.FC = () => {
const { paymentTokens, handleRemovePaymentToken } = useSettings();

console.log(paymentTokens);

return paymentTokens && paymentTokens.payment_tokens ? (
<table cellPadding={5}>
<thead>
Expand Down

0 comments on commit a8eed53

Please sign in to comment.