From 9bd3e54a10849e18d284a8917838710cc5b34b56 Mon Sep 17 00:00:00 2001 From: Sanskar Atrey Date: Wed, 18 Sep 2024 22:34:47 +0530 Subject: [PATCH] refactor: formatted code --- .../cypress/e2e/card-flow-e2e-test.cy.ts | 38 +++++++++---------- cypress-tests/cypress/support/commands.ts | 10 ++--- cypress-tests/cypress/support/types.ts | 4 +- cypress-tests/cypress/support/utils.ts | 8 ++-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/cypress-tests/cypress/e2e/card-flow-e2e-test.cy.ts b/cypress-tests/cypress/e2e/card-flow-e2e-test.cy.ts index f6769d708..c0131cb74 100644 --- a/cypress-tests/cypress/e2e/card-flow-e2e-test.cy.ts +++ b/cypress-tests/cypress/e2e/card-flow-e2e-test.cy.ts @@ -5,23 +5,23 @@ import { changeObjectKeyValue } from "../support/utils"; describe("Card payment flow test", () => { - const publishableKey=Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY') - const secretKey=Cypress.env('HYPERSWITCH_SECRET_KEY') - let getIframeBody : () => Cypress.Chainable>; + const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY') + const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY') + let getIframeBody: () => Cypress.Chainable>; let iframeSelector = - "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; + "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; - // changeObjectKeyValue(createPaymentBody,"profile_id","YOUR_PROFILE_ID") + // changeObjectKeyValue(createPaymentBody,"profile_id","YOUR_PROFILE_ID") beforeEach(() => { getIframeBody = () => cy.iframe(iframeSelector); - cy.createPaymentIntent(secretKey,createPaymentBody).then(()=>{ - cy.getGlobalState("clientSecret").then((clientSecret)=>{ + cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { + cy.getGlobalState("clientSecret").then((clientSecret) => { - cy.visit(getClientURL(clientSecret,publishableKey)); + cy.visit(getClientURL(clientSecret, publishableKey)); }); - + }) }); @@ -42,15 +42,15 @@ describe("Card payment flow test", () => { it('should check if cards are saved', () => { // Visit the page where the test will be performed getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`) - .then($element => { - if ($element.length > 0) { - getIframeBody().find('[data-testid=cvvInput]').type('123'); - getIframeBody().get("#submit").click(); - cy.wait(2000); - cy.contains("Thanks for your order!").should("be.visible"); - } else { - cy.log(' new card card flow'); - } - }); + .then($element => { + if ($element.length > 0) { + getIframeBody().find('[data-testid=cvvInput]').type('123'); + getIframeBody().get("#submit").click(); + cy.wait(2000); + cy.contains("Thanks for your order!").should("be.visible"); + } else { + cy.log(' new card card flow'); + } + }); }); }); diff --git a/cypress-tests/cypress/support/commands.ts b/cypress-tests/cypress/support/commands.ts index 9f92541c0..5a3fe36e2 100644 --- a/cypress-tests/cypress/support/commands.ts +++ b/cypress-tests/cypress/support/commands.ts @@ -24,10 +24,10 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) import "cypress-iframe"; -import {createPaymentBody} from "./utils" +import { createPaymentBody } from "./utils" import * as testIds from "../../../src/Utilities/TestUtils.bs"; // commands.js or your custom support file -const iframeSelector = +const iframeSelector = "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; let globalState = {}; @@ -74,11 +74,11 @@ Cypress.Commands.add( mapping[testIds.cardNoInputTestId] = customerData.threeDSCardNo; } let publishableKey = "pk_snd_3b33cd9404234113804aa1accaabe22f"; - let clientSecret:string; + let clientSecret: string; cy.request({ method: "GET", url: "http://localhost:5252/create-payment-intent", - }).then((response: {body: { clientSecret: string }}) => { + }).then((response: { body: { clientSecret: string } }) => { clientSecret = response.body.clientSecret; cy.request({ @@ -147,7 +147,7 @@ Cypress.Commands.add( ); -Cypress.Commands.add("createPaymentIntent", (secretKey:string,createPaymentBody:any) => { +Cypress.Commands.add("createPaymentIntent", (secretKey: string, createPaymentBody: any) => { return cy .request({ method: "POST", diff --git a/cypress-tests/cypress/support/types.ts b/cypress-tests/cypress/support/types.ts index 0152c59d3..d1db388d1 100644 --- a/cypress-tests/cypress/support/types.ts +++ b/cypress-tests/cypress/support/types.ts @@ -1,5 +1,5 @@ -export {}; // indicate that file is a module +export { }; // indicate that file is a module export type CustomerData = { cardNo: string @@ -24,7 +24,7 @@ declare global { testDynamicFields( customerData: CustomerData, testIdsToRemoveArr: string[], isThreeDSEnabled: boolean ): Chainable> - createPaymentIntent(secretKey:string,createPaymentBody:Record ): Chainable> + createPaymentIntent(secretKey: string, createPaymentBody: Record): Chainable> getGlobalState(key: string): Chainable> } } diff --git a/cypress-tests/cypress/support/utils.ts b/cypress-tests/cypress/support/utils.ts index f7b555a5b..ae0982a52 100644 --- a/cypress-tests/cypress/support/utils.ts +++ b/cypress-tests/cypress/support/utils.ts @@ -2,12 +2,12 @@ export const CLIENT_BASE_URL = "http://localhost:9060" -export const getClientURL=(clientSecret,publishableKey)=>{ +export const getClientURL = (clientSecret, publishableKey) => { return `${CLIENT_BASE_URL}?isCypressTestMode=true&clientSecret=${clientSecret}&publishableKey=${publishableKey}`; } -export const createPaymentBody ={ +export const createPaymentBody = { currency: "USD", amount: 2999, order_details: [ @@ -68,8 +68,8 @@ export const createPaymentBody ={ } -export const changeObjectKeyValue=(object:Record ,key:string,value:string)=>{ - object[key]=value +export const changeObjectKeyValue = (object: Record, key: string, value: string) => { + object[key] = value } export const confirmBody = {