Skip to content

Commit

Permalink
refactor: formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanskar2001 committed Sep 18, 2024
1 parent 3ec5858 commit 9bd3e54
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
38 changes: 19 additions & 19 deletions cypress-tests/cypress/e2e/card-flow-e2e-test.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JQuery<HTMLBodyElement>>;
const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY')
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY')
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
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));
});

})
});

Expand All @@ -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');
}
});
});
});
10 changes: 5 additions & 5 deletions cypress-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions cypress-tests/cypress/support/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export {}; // indicate that file is a module
export { }; // indicate that file is a module

export type CustomerData = {
cardNo: string
Expand All @@ -24,7 +24,7 @@ declare global {
testDynamicFields(
customerData: CustomerData, testIdsToRemoveArr: string[], isThreeDSEnabled: boolean
): Chainable<JQuery<HTMLElement>>
createPaymentIntent(secretKey:string,createPaymentBody:Record<string, any> ): Chainable<Response<any>>
createPaymentIntent(secretKey: string, createPaymentBody: Record<string, any>): Chainable<Response<any>>
getGlobalState(key: string): Chainable<Response<any>>
}
}
Expand Down
8 changes: 4 additions & 4 deletions cypress-tests/cypress/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -68,8 +68,8 @@ export const createPaymentBody ={

}

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

export const confirmBody = {
Expand Down

0 comments on commit 9bd3e54

Please sign in to comment.