From 09352da27d6581a40d800a46f5560e1edf44ce6a Mon Sep 17 00:00:00 2001 From: "aritro.ghosh" Date: Mon, 16 Dec 2024 17:51:16 +0530 Subject: [PATCH] fix: apply suggested changes --- .../cypress/e2e/dynamic-field-test.cy.ts | 60 +++++++++++++------ cypress-tests/cypress/support/utils.ts | 46 ++------------ 2 files changed, 47 insertions(+), 59 deletions(-) diff --git a/cypress-tests/cypress/e2e/dynamic-field-test.cy.ts b/cypress-tests/cypress/e2e/dynamic-field-test.cy.ts index c8d60507..94ab2aa9 100644 --- a/cypress-tests/cypress/e2e/dynamic-field-test.cy.ts +++ b/cypress-tests/cypress/e2e/dynamic-field-test.cy.ts @@ -1,4 +1,4 @@ -import { getClientURL, createPaymentBodyWithoutBillingAddress } from "../support/utils"; +import { getClientURL, createPaymentBody, deleteObjectKey } from "../support/utils"; describe("Dynamic Field Test", () => { let getIframeBody; @@ -6,10 +6,12 @@ describe("Dynamic Field Test", () => { 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)); @@ -17,9 +19,8 @@ describe("Dynamic Field Test", () => { }); }); - 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); @@ -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; }); }); diff --git a/cypress-tests/cypress/support/utils.ts b/cypress-tests/cypress/support/utils.ts index 88b2f367..943fa478 100644 --- a/cypress-tests/cypress/support/utils.ts +++ b/cypress-tests/cypress/support/utils.ts @@ -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: "hyperswitch_sdk_demo_id@gmail.com", - 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, key: string, value: boolean | string) => { object[key] = value } +export const deleteObjectKey = (object: Record, key: string) => { + delete object[key] +} + export const confirmBody = { client_secret: "", return_url: "http://localhost:9060/completion",