Skip to content

Commit

Permalink
fix: apply suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aritro2002 committed Dec 16, 2024
1 parent a9f773b commit 09352da
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 59 deletions.
60 changes: 43 additions & 17 deletions cypress-tests/cypress/e2e/dynamic-field-test.cy.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { getClientURL, createPaymentBodyWithoutBillingAddress } from "../support/utils";
import { getClientURL, createPaymentBody, deleteObjectKey } from "../support/utils";

describe("Dynamic Field Test", () => {
let getIframeBody;
let globalClientSecret;
const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY');
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY');
const iframeSelector = "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";
deleteObjectKey(createPaymentBody, "shipping");
deleteObjectKey(createPaymentBody, "billing");

beforeEach(() => {
getIframeBody = () => cy.iframe(iframeSelector);
cy.createPaymentIntent(secretKey, createPaymentBodyWithoutBillingAddress).then(() => {
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
cy.getGlobalState("clientSecret").then((clientSecret) => {
globalClientSecret = clientSecret;
cy.visit(getClientURL(clientSecret, publishableKey));
});
});
});

it("should check that required address fields are set null for 'payment_method_type' = 'debit'", () => {
it("should check that required address fields are set null for payment_method_type as 'debit' and 'paypal'", () => {
cy.intercept('GET', `https://sandbox.hyperswitch.io/account/payment_methods?client_secret=${globalClientSecret}`).as('getPaymentMethods');

cy.wait('@getPaymentMethods').then(({ response }) => {
expect(response.statusCode).to.eq(200);

Expand All @@ -29,27 +30,52 @@ describe("Dynamic Field Test", () => {
method.payment_method_types.some(type => type.payment_method_type === 'debit')
);

const paypalMethod = paymentMethods.find(method =>
method.payment_method_types.some(type => type.payment_method_type === 'paypal')
);

expect(debitMethod).to.not.be.undefined;
expect(paypalMethod).to.not.be.undefined;

const requiredFields = debitMethod.payment_method_types.find(type => type.payment_method_type === 'debit').required_fields;
const debitRequiredFields = debitMethod.payment_method_types.find(type => type.payment_method_type === 'debit').required_fields;
const paypalRequiredFields = paypalMethod.payment_method_types.find(type => type.payment_method_type === 'paypal').required_fields;


expect(requiredFields).to.have.property('billing.address.state');
expect(requiredFields['billing.address.state'].value).to.be.null;
expect(debitRequiredFields).to.have.property('billing.address.state');
expect(debitRequiredFields['billing.address.state'].value).to.be.null;

expect(debitRequiredFields).to.have.property('billing.address.country');
expect(debitRequiredFields['billing.address.country'].value).to.be.null;

expect(debitRequiredFields).to.have.property('billing.address.line1');
expect(debitRequiredFields['billing.address.line1'].value).to.be.null;

expect(debitRequiredFields).to.have.property('billing.address.zip');
expect(debitRequiredFields['billing.address.zip'].value).to.be.null;

expect(debitRequiredFields).to.have.property('billing.address.last_name');
expect(debitRequiredFields['billing.address.last_name'].value).to.be.null;

expect(debitRequiredFields).to.have.property('billing.address.city');
expect(debitRequiredFields['billing.address.city'].value).to.be.null;

expect(paypalRequiredFields).to.have.property('shipping.address.state');
expect(paypalRequiredFields['shipping.address.state'].value).to.be.null;

expect(requiredFields).to.have.property('billing.address.country');
expect(requiredFields['billing.address.country'].value).to.be.null;
expect(paypalRequiredFields).to.have.property('shipping.address.country');
expect(paypalRequiredFields['shipping.address.country'].value).to.be.null;

expect(requiredFields).to.have.property('billing.address.line1');
expect(requiredFields['billing.address.line1'].value).to.be.null;
expect(paypalRequiredFields).to.have.property('shipping.address.line1');
expect(paypalRequiredFields['shipping.address.line1'].value).to.be.null;

expect(requiredFields).to.have.property('billing.address.zip');
expect(requiredFields['billing.address.zip'].value).to.be.null;
expect(paypalRequiredFields).to.have.property('shipping.address.zip');
expect(paypalRequiredFields['shipping.address.zip'].value).to.be.null;

expect(requiredFields).to.have.property('billing.address.last_name');
expect(requiredFields['billing.address.last_name'].value).to.be.null;
expect(paypalRequiredFields).to.have.property('shipping.address.last_name');
expect(paypalRequiredFields['shipping.address.last_name'].value).to.be.null;

expect(requiredFields).to.have.property('billing.address.city');
expect(requiredFields['billing.address.city'].value).to.be.null;
expect(paypalRequiredFields).to.have.property('shipping.address.city');
expect(paypalRequiredFields['shipping.address.city'].value).to.be.null;

});
});
Expand Down
46 changes: 4 additions & 42 deletions cypress-tests/cypress/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,52 +80,14 @@ export const createPaymentBody = {

}

export const createPaymentBodyWithoutBillingAddress = {
currency: "USD",
amount: 2999,
order_details: [
{
product_name: "Apple iPhone 15",
quantity: 1,
amount: 2999,
},
],
confirm: false,
capture_method: "automatic",
authentication_type: "no_three_ds",
customer_id: "hyperswitch_sdk_demo_id",
email: "[email protected]",
request_external_three_ds_authentication: false,
description: "Hello this is description",
shipping: {
address: {
line1: "1467",
line2: "Harrison Street",
line3: "Harrison Street",
city: "San Fransico",
state: "California",
zip: "94122",
country: "US",
first_name: "joseph",
last_name: "Doe",
},
phone: {
number: "8056594427",
country_code: "+91",
},
},
metadata: {
udf1: "value1",
new_customer: "true",
login_date: "2019-09-10T10:11:12Z",
},
profile_id: "pro_5fVcCxU8MFTYozgtf0P8",
}

export const changeObjectKeyValue = (object: Record<string, any>, key: string, value: boolean | string) => {
object[key] = value
}

export const deleteObjectKey = (object: Record<string, any>, key: string) => {
delete object[key]
}

export const confirmBody = {
client_secret: "",
return_url: "http://localhost:9060/completion",
Expand Down

0 comments on commit 09352da

Please sign in to comment.