|
| 1 | +import * as testIds from "../../../src/Utilities/TestUtils.bs"; |
| 2 | +import { getClientURL } from "../support/utils"; |
| 3 | +import { createPaymentBody } from "../support/utils"; |
| 4 | +import { changeObjectKeyValue } from "../support/utils"; |
| 5 | +import { trustpayCards } from "cypress/support/cards"; |
| 6 | +import { connectorEnum, connectorProfileIdMapping } from "../support/utils"; |
| 7 | + |
| 8 | +describe("Trustpay Card Payment flow test", () => { |
| 9 | + const publishableKey = Cypress.env("HYPERSWITCH_PUBLISHABLE_KEY"); |
| 10 | + const secretKey = Cypress.env("HYPERSWITCH_SECRET_KEY"); |
| 11 | + let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>; |
| 12 | + let iframeSelector = |
| 13 | + "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + getIframeBody = () => cy.iframe(iframeSelector); |
| 17 | + changeObjectKeyValue( |
| 18 | + createPaymentBody, |
| 19 | + "profile_id", |
| 20 | + connectorProfileIdMapping.get(connectorEnum.TRUSTPAY), |
| 21 | + ); |
| 22 | + }); |
| 23 | + |
| 24 | + it("should complete the card payment successfully (No 3DS)", () => { |
| 25 | + changeObjectKeyValue( |
| 26 | + createPaymentBody, |
| 27 | + "authentication_type", |
| 28 | + "no_three_ds", |
| 29 | + ); |
| 30 | + changeObjectKeyValue(createPaymentBody, "customer_id", "new_customer_id"); |
| 31 | + cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { |
| 32 | + cy.getGlobalState("clientSecret").then((clientSecret) => { |
| 33 | + cy.visit(getClientURL(clientSecret, publishableKey)); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + const { cardNo, card_exp_month, card_exp_year, cvc } = |
| 38 | + trustpayCards.successCard; |
| 39 | + |
| 40 | + getIframeBody().find("[data-testid=cardNoInput]").type(cardNo); |
| 41 | + getIframeBody().find("[data-testid=expiryInput]").type(card_exp_month); |
| 42 | + getIframeBody().find("[data-testid=expiryInput]").type(card_exp_year); |
| 43 | + getIframeBody().find("[data-testid=cvvInput]").type(cvc); |
| 44 | + |
| 45 | + getIframeBody().get("#submit").click(); |
| 46 | + |
| 47 | + cy.wait(3000); |
| 48 | + cy.contains("Thanks for your order!").should("be.visible"); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should show the 3DS challenge page", () => { |
| 52 | + changeObjectKeyValue(createPaymentBody, "authentication_type", "three_ds"); |
| 53 | + cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { |
| 54 | + cy.getGlobalState("clientSecret").then((clientSecret) => { |
| 55 | + cy.visit(getClientURL(clientSecret, publishableKey)); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + const { cardNo, card_exp_month, card_exp_year, cvc } = |
| 60 | + trustpayCards.threeDSCard; |
| 61 | + |
| 62 | + getIframeBody().find("[data-testid=cardNoInput]").type(cardNo); |
| 63 | + getIframeBody().find("[data-testid=expiryInput]").type(card_exp_month); |
| 64 | + getIframeBody().find("[data-testid=expiryInput]").type(card_exp_year); |
| 65 | + getIframeBody().find("[data-testid=cvvInput]").type(cvc); |
| 66 | + |
| 67 | + getIframeBody().get("#submit").click(); |
| 68 | + cy.wait(3000); |
| 69 | + |
| 70 | + cy.get("body").then(($body) => { |
| 71 | + if ($body.find("#tp-iframe").length > 0) { |
| 72 | + cy.iframe("#tp-iframe").should("be.visible"); |
| 73 | + } |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + it("should fail with an invalid card number", () => { |
| 78 | + changeObjectKeyValue( |
| 79 | + createPaymentBody, |
| 80 | + "authentication_type", |
| 81 | + "no_three_ds", |
| 82 | + ); |
| 83 | + cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { |
| 84 | + cy.getGlobalState("clientSecret").then((clientSecret) => { |
| 85 | + cy.visit(getClientURL(clientSecret, publishableKey)); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + const { cardNo, card_exp_month, card_exp_year, cvc } = |
| 90 | + trustpayCards.invalidCard; |
| 91 | + |
| 92 | + getIframeBody().find("[data-testid=cardNoInput]").type(cardNo); |
| 93 | + getIframeBody().find("[data-testid=expiryInput]").type(card_exp_month); |
| 94 | + getIframeBody().find("[data-testid=expiryInput]").type(card_exp_year); |
| 95 | + getIframeBody().find("[data-testid=cvvInput]").type(cvc); |
| 96 | + |
| 97 | + getIframeBody().get("#submit").click(); |
| 98 | + |
| 99 | + cy.wait(3000); |
| 100 | + cy.contains("Please enter valid details").should("be.visible"); |
| 101 | + }); |
| 102 | +}); |
0 commit comments