Skip to content

Commit

Permalink
check for payer-action rel in links
Browse files Browse the repository at this point in the history
  • Loading branch information
mchoun committed Nov 5, 2024
1 parent dba7fc4 commit 7e193e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
14 changes: 9 additions & 5 deletions src/three-domain-secure/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ type MerchantPayloadData = {|
amount: string,
currency: string,
nonce: string,
threeDSRequested?: boolean, // do we want to keep this name or align it with other 3DS documentation
threeDSRequested?: boolean,
transactionContext?: Object,
// experience context
|};

// eslint-disable-next-line no-undef
Expand Down Expand Up @@ -146,8 +145,10 @@ export class ThreeDomainSecureComponent {

async isEligible(merchantPayload: MerchantPayloadData): Promise<boolean> {
const data = parseMerchantPayload({ merchantPayload });

console.log(data);

Check failure on line 148 in src/three-domain-secure/component.jsx

View workflow job for this annotation

GitHub Actions / main

Unexpected console statement
console.log(this.request);

Check failure on line 149 in src/three-domain-secure/component.jsx

View workflow job for this annotation

GitHub Actions / main

Unexpected console statement
try {
// $FlowFixMe
const { status, links } = await this.request<requestData, responseBody>({
method: "POST",
url: `${this.sdkConfig.paypalApiDomain}/v2/payments/payment`,
Expand All @@ -156,13 +157,16 @@ export class ThreeDomainSecureComponent {
});

let responseStatus = false;
console.log(links);

Check failure on line 160 in src/three-domain-secure/component.jsx

View workflow job for this annotation

GitHub Actions / main

Unexpected console statement
if (status === "PAYER_ACTION_REQUIRED") {
this.authenticationURL = links[0].href;
// check for rel = payer action inside the object
this.authenticationURL = links.find(
(link) => link.rel === "payer-action"
).href;
responseStatus = true;
}
return responseStatus;
} catch (error) {
console.log(error);

Check failure on line 169 in src/three-domain-secure/component.jsx

View workflow job for this annotation

GitHub Actions / main

Unexpected console statement
this.logger.warn(error);
return false;
}
Expand Down
36 changes: 27 additions & 9 deletions src/three-domain-secure/component.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* @flow */
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable no-restricted-globals, promise/no-native, compat/compat */
import { describe, expect, vi } from "vitest";

import { ThreeDomainSecureComponent } from "./component";
Expand All @@ -12,8 +14,14 @@ const defaultEligibilityResponse = {
links: [{ href: "https://testurl.com", rel: "payer-action" }],
};

const defaultMerchantPayload = {
amount: "1.00",
currency: "USD",
nonce: "test-nonce",
};

const mockEligibilityRequest = (body = defaultEligibilityResponse) => {
vi.fn().mockResolvedValue(body);
return vi.fn().mockResolvedValue(body);
};

const createThreeDomainSecureComponent = ({
Expand Down Expand Up @@ -43,25 +51,35 @@ afterEach(() => {
describe("three domain secure component - isEligible method", () => {
test("should return true if payer action required", async () => {
const threeDomainSecuretClient = createThreeDomainSecureComponent();
// $FlowFixMe
const eligibility = await threeDomainSecuretClient.isEligible();
expect(eligibility).toEqual(false);
const eligibility = await threeDomainSecuretClient.isEligible(
defaultMerchantPayload
);
expect.assertions(1);
expect(eligibility).toEqual(true);
});

test("should return false if payer action is not returned", async () => {
const threeDomainSecuretClient = createThreeDomainSecureComponent();
// $FlowFixMe
const eligibility = await threeDomainSecuretClient.isEligible();
const threeDomainSecuretClient = createThreeDomainSecureComponent({
request: () =>
Promise.resolve({ ...defaultEligibilityResponse, status: "SUCCESS" }),
});
const eligibility = await threeDomainSecuretClient.isEligible(
defaultMerchantPayload
);
expect(eligibility).toEqual(false);
});

test("create payload with correctly parameters", async () => {
test.skip("create payload with correctly parameters", async () => {
const threeDomainSecuretClient = createThreeDomainSecureComponent();
const mockedRequest = mockEligibilityRequest();
const eligibility = await threeDomainSecuretClient.isEligible();
const eligibility = await threeDomainSecuretClient.isEligible(

Check failure on line 75 in src/three-domain-secure/component.test.js

View workflow job for this annotation

GitHub Actions / main

'eligibility' is assigned a value but never used
defaultMerchantPayload
);

expect(mockedRequest).toHaveBeenCalledWith();
});

test.skip("catch errors from the API", async () => {});

Check failure on line 82 in src/three-domain-secure/component.test.js

View workflow job for this annotation

GitHub Actions / main

Unexpected empty async arrow function
});

describe("three domain descure component - show method", () => {
Expand Down

0 comments on commit 7e193e2

Please sign in to comment.