Skip to content

Commit

Permalink
feat: added nested iframe test support in cypress and external 3ds ne…
Browse files Browse the repository at this point in the history
…tcetera test case
  • Loading branch information
Sanskar2001 committed Nov 4, 2024
1 parent f55f61a commit 139a62f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
81 changes: 81 additions & 0 deletions cypress-tests/cypress/e2e/external-3DS-netcetera-e2e-test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as testIds from "../../../src/Utilities/TestUtils.bs";
import { getClientURL, netceteraChallengeTestCard, createPaymentBody, changeObjectKeyValue, connectorProfileIdMapping, connectorEnum } from "../support/utils";
describe("External 3DS using Netcetera Checks", () => {
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY')
const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY')
changeObjectKeyValue(createPaymentBody, "profile_id", connectorProfileIdMapping.get(connectorEnum.NETCETERA))
changeObjectKeyValue(createPaymentBody, "request_external_three_ds_authentication", true)
changeObjectKeyValue(createPaymentBody, "authentication_type", "three_ds")
let iframeSelector =
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";

beforeEach(() => {
getIframeBody = () => cy.iframe(iframeSelector);
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
cy.getGlobalState("clientSecret").then((clientSecret) => {

cy.visit(getClientURL(clientSecret, publishableKey));
});

})
});


it("title rendered correctly", () => {
cy.contains("Hyperswitch Unified Checkout").should("be.visible");
});

it("orca-payment-element iframe loaded", () => {
cy.get(
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"
)
.should("be.visible")
.its("0.contentDocument")
.its("body");
});


it('If the user completes the challenge, the payment should be successful.', () => {
getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`).click()
getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(netceteraChallengeTestCard)
getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type("0444")
cy.wait(1000)
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type("1234")
getIframeBody().get("#submit").click();
cy.wait(4000)

cy.nestedIFrame("#threeDsAuthFrame", ($body) => {
cy.wrap($body).find('#otp')
.type('1234')

cy.wrap($body).find('#sendOtp')
.click()
cy.contains("Thanks for your order!").should("be.visible");
})

})

it('If the user closes the challenge, the payment should fail.', () => {
getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`).click()
getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(netceteraChallengeTestCard)
getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type("0444")
cy.wait(1000)
getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type("1234")
getIframeBody().get("#submit").click();
cy.wait(4000)

cy.nestedIFrame("#threeDsAuthFrame", ($body) => {
cy.wrap($body)
.find('#cancel')
.click()
cy.contains("Payment Failed!").should("be.visible");
})
})


})




8 changes: 8 additions & 0 deletions cypress-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,11 @@ Cypress.Commands.add("createPaymentIntent", (secretKey: string, createPaymentBod
Cypress.Commands.add("getGlobalState", (key: any) => {
return globalState[key];
});

Cypress.Commands.add("nestedIFrame", (selector, callback) => {
cy.iframe("#orca-fullscreen").find(selector).should("exist").should("be.visible").then(($ele) => {
const $body =
$ele.contents().find('body')
callback($body);
})
});
1 change: 1 addition & 0 deletions cypress-tests/cypress/support/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare global {
): Chainable<JQuery<HTMLElement>>
createPaymentIntent(secretKey: string, createPaymentBody: Record<string, any>): Chainable<Response<any>>
getGlobalState(key: string): Chainable<Response<any>>
nestedIFrame(selector: string, callback: (body: Chainable<JQuery<HTMLElement>>) => void): Chainable<void>;
}
}
}
9 changes: 6 additions & 3 deletions cypress-tests/cypress/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ export const getClientURL = (clientSecret, publishableKey) => {
return `${CLIENT_BASE_URL}?isCypressTestMode=true&clientSecret=${clientSecret}&publishableKey=${publishableKey}`;
}

export const enum connectorEnum{
export const enum connectorEnum {
TRUSTPAY,
ADYEN,
STRIPE
STRIPE,
NETCETERA
}
export const connectorProfileIdMapping = new Map<connectorEnum, string>([
[connectorEnum.TRUSTPAY, "pro_eP323T9e4ApKpilWBfPA"],
[connectorEnum.ADYEN, "pro_Kvqzu8WqBZsT1OjHlCj4"],
[connectorEnum.STRIPE, "pro_5fVcCxU8MFTYozgtf0P8"],
[connectorEnum.NETCETERA, "pro_h9VHXnJx8s6W4KSZfSUL"]
]);

export const createPaymentBody = {
Expand Down Expand Up @@ -78,7 +80,7 @@ export const createPaymentBody = {

}

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

Expand Down Expand Up @@ -128,3 +130,4 @@ export const adyenTestCard = "4917610000000000";
export const bluesnapTestCard = "4000000000001091";
export const amexTestCard = "378282246310005"
export const visaTestCard = "4242424242424242";
export const netceteraChallengeTestCard = "348638267931507";

0 comments on commit 139a62f

Please sign in to comment.