Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
test(cypress): add Payment Method Collect Link coverage (#12041)
HS-QUALIBOTd89dc1eaa60f
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.jsindex 44bfc9d9a6..58fdbf95b2 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js@@ -3672,6 +3672,33 @@ export const connectorDetails = {},}),},+ pm_collect_link: {+ pmCollectLinkCreate: {+ Request: {+ return_url: "https://example.com/return",+ },+ Response: {+ status: 200,+ },+ },+ pmCollectLinkRender: {+ Response: {+ status: 200,+ },+ },+ pmCollectLinkRenderNotFound: {+ Response: {+ status: 404,+ body: {+ error: {+ type: "invalid_request",+ code: "IR_37",+ message: "payment method collect link not found",+ },+ },+ },+ },+ },payment_link_pm: {PaymentLinkBasic: getCustomExchange({Request: {diff --git a/cypress-tests/cypress/e2e/spec/Payment/00-CoreFlows.cy.js b/cypress-tests/cypress/e2e/spec/Payment/00-CoreFlows.cy.jsindex 02e360c0c6..dfd822e2fa 100644--- a/cypress-tests/cypress/e2e/spec/Payment/00-CoreFlows.cy.js+++ b/cypress-tests/cypress/e2e/spec/Payment/00-CoreFlows.cy.js@@ -1,7 +1,12 @@import * as fixtures from "../../../fixtures/imports";import State from "../../../utils/State";import getConnectorDetails, * as utils from "../../configs/Payment/Utils";-import { payment_methods_enabled } from "../../configs/Payment/Commons";+import {+ payment_methods_enabled,+ connectorDetails as paymentCommonDetails,+} from "../../configs/Payment/Commons";++const pmCollectLinkConnectorDetails = paymentCommonDetails.pm_collect_link;let globalState;@@ -279,4 +284,100 @@ describe("Core flows", () => {cy.ListConnectorsFeatureMatrixCall(globalState);});});++ context("Payment Method Collect Link core flows", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ it("Payment method collect link create and render", () => {+ const shouldContinue = true;++ cy.step("Create merchant account", () => {+ cy.merchantCreateCallTest(fixtures.merchantCreateBody, globalState);+ });++ cy.step("Create merchant API key", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: Create merchant API key");+ return;+ }+ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);+ });++ cy.step("Create customer", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: Create customer");+ return;+ }+ cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);+ });++ cy.step("Initiate Payment Method Collect Link", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Initiate Payment Method Collect Link"+ );+ return;+ }+ cy.paymentMethodCollectLinkCreate(+ fixtures.pmCollectLinkBody,+ pmCollectLinkConnectorDetails.pmCollectLinkCreate,+ globalState+ );+ });++ cy.step("Render Payment Method Collect Form", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Render Payment Method Collect Form"+ );+ return;+ }+ cy.paymentMethodCollectLinkRender(+ pmCollectLinkConnectorDetails.pmCollectLinkRender,+ globalState+ );+ });+ });++ it("Payment method collect link render with invalid id", () => {+ const shouldContinue = true;++ cy.step("Create merchant account", () => {+ cy.merchantCreateCallTest(fixtures.merchantCreateBody, globalState);+ });++ cy.step("Create merchant API key", () => {+ if (!shouldContinue) {+ cy.task("cli_log", "Skipping step: Create merchant API key");+ return;+ }+ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);+ });++ cy.step("Set invalid collect id and attempt render", () => {+ if (!shouldContinue) {+ cy.task(+ "cli_log",+ "Skipping step: Set invalid collect id and attempt render"+ );+ return;+ }+ globalState.set("pmCollectId", "invalid_collect_id_12345");+ cy.paymentMethodCollectLinkRender(+ pmCollectLinkConnectorDetails.pmCollectLinkRenderNotFound,+ globalState+ );+ });+ });+ });});diff --git a/cypress-tests/cypress/fixtures/imports.js b/cypress-tests/cypress/fixtures/imports.jsindex 9f658bd42d..559935033b 100644--- a/cypress-tests/cypress/fixtures/imports.js+++ b/cypress-tests/cypress/fixtures/imports.js@@ -26,6 +26,7 @@ import customerUpdateBody from "./update-customer-body.json";import voidBody from "./void-payment-body.json";import ntidConfirmBody from "./create-ntid-mit.json";import blocklistCreateBody from "./blocklist-create-body.json";+import pmCollectLinkBody from "./pm-collect-link-body.json";import disputeEvidenceBody from "./dispute-evidence-body.json";import cardLimitedDataMITBody from "./create-card-limited-data-mit.json";import eligibilityCheckBody from "./eligibility-check-body.json";@@ -83,4 +84,5 @@ export {paymentMethodSessionUpdate,paymentMethodSessionConfirm,modularPmServicePaymentsCall,+ pmCollectLinkBody,};diff --git a/cypress-tests/cypress/fixtures/pm-collect-link-body.json b/cypress-tests/cypress/fixtures/pm-collect-link-body.jsonnew file mode 100644index 0000000000..5f20e60451--- /dev/null+++ b/cypress-tests/cypress/fixtures/pm-collect-link-body.json@@ -0,0 +1,4 @@+{+ "customer_id": "",+ "return_url": "https://example.com/return"+}diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex e1558d4d29..9d3326b306 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -8427,6 +8427,103 @@ Cypress.Commands.add("verifyIframeRedirection", (globalState, options = {}) => {.be.null;}});+// ============================================+// Payment Method Collect Link Commands+// ============================================++Cypress.Commands.add(+ "paymentMethodCollectLinkCreate",+ (requestBody, data, globalState) => {+ const { Request: reqData, Response: resData } = data || {};++ const apiKey = globalState.get("apiKey");+ const baseUrl = globalState.get("baseUrl");+ const customerId = globalState.get("customerId");+ const url = `${baseUrl}/payment_methods/collect`;++ const body = {+ ...requestBody,+ ...reqData,+ customer_id: customerId,+ };++ cy.request({+ method: "POST",+ url: url,+ headers: {+ "Content-Type": "application/json",+ "api-key": apiKey,+ },+ body: body,+ failOnStatusCode: false,+ }).then((response) => {+ logRequestId(response.headers["x-request-id"]);++ cy.wrap(response).then(() => {+ expect(response.headers["content-type"]).to.include("application/json");++ if (response.status === 200) {+ globalState.set("pmCollectId", response.body.pm_collect_link_id);+ globalState.set("pmCollectLink", response.body.link);++ expect(response.body).to.have.property("pm_collect_link_id").and.not+ .be.empty;+ expect(response.body).to.have.property("link").and.not.be.empty;+ expect(response.body).to.have.property("customer_id").and.not.be+ .empty;+ }++ if (resData && resData.body) {+ for (const key in resData.body) {+ if (resData.body[key] !== undefined) {+ expect(response.body[key]).to.deep.equal(resData.body[key]);+ }+ }+ }+ });+ });+ }+);++Cypress.Commands.add("paymentMethodCollectLinkRender", (data, globalState) => {+ const { Response: resData } = data || {};++ const baseUrl = globalState.get("baseUrl");+ const merchantId = globalState.get("merchantId");+ const pmCollectId = globalState.get("pmCollectId");++ if (!pmCollectId) {+ cy.log("No pmCollectId found in globalState, skipping render call");+ return;+ }++ const url = `${baseUrl}/payment_methods/collect/${merchantId}/${pmCollectId}`;++ cy.request({+ method: "GET",+ url: url,+ headers: {+ "Content-Type": "application/json",+ },+ failOnStatusCode: false,+ }).then((response) => {+ logRequestId(response.headers["x-request-id"]);++ cy.wrap(response).then(() => {+ if (response.status === 200) {+ expect(response.headers["content-type"]).to.include("text/html");+ expect(response.body).to.be.a("string");+ } else if (response.status === 400 || response.status === 404) {+ if (resData && resData.body) {+ for (const key in resData.body) {+ expect(response.body[key]).to.deep.equal(resData.body[key]);+ }+ }+ }+ });+ });+});+// ============================================// Payment Link Commands// ============================================@@ -8506,6 +8603,8 @@ Cypress.Commands.add(});+// ============================================+// OIDC Authentication Commands// ============================================// OIDC Authentication Commands// ============================================