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
ci(cypress): add test cases for duplicate requests (#7220)
likhinbopanna8bb94afdc4ba
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.jsindex 0f551c97c6..6cf29db5f1 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js@@ -1470,6 +1470,44 @@ export const connectorDetails = {},},},+ DuplicatePaymentID: {+ Request: {+ payment_method: "card",+ payment_method_data: {+ card: successfulNo3DSCardDetails,+ },+ currency: "USD",+ customer_acceptance: null,+ setup_future_usage: "on_session",+ },+ Response: {+ status: 400,+ body: {+ error: {+ type: "invalid_request",+ message:+ "The payment with the specified payment_id already exists in our records",+ code: "HE_01",+ },+ },+ },+ },+ DuplicateRefundID: {+ Request: {+ amount: 2000,+ },+ Response: {+ status: 400,+ body: {+ error: {+ type: "invalid_request",+ message:+ "Duplicate refund request. Refund already attempted with the refund ID",+ code: "HE_01",+ },+ },+ },+ },},upi_pm: {PaymentIntent: getCustomExchange({diff --git a/cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js b/cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.jsindex f3a99df1ba..8180f30bd4 100644--- a/cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js+++ b/cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js@@ -702,4 +702,117 @@ describe("Corner cases", () => {if (shouldContinue) shouldContinue = utils.should_continue_further(data);});});++ context("Duplicate Payment ID", () => {+ let shouldContinue = true; // variable that will be used to skip tests if a previous test fails++ beforeEach(function () {+ if (!shouldContinue) {+ this.skip();+ }+ });++ it("Create new payment", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["No3DSAutoCapture"];++ cy.createConfirmPaymentTest(+ fixtures.createConfirmPaymentBody,+ data,+ "no_three_ds",+ "automatic",+ globalState+ );+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("Retrieve payment", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["No3DSAutoCapture"];++ cy.retrievePaymentCallTest(globalState, data);+ });++ it("Create a payment with a duplicate payment ID", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["DuplicatePaymentID"];++ data.Request.payment_id = globalState.get("paymentID");++ cy.createConfirmPaymentTest(+ fixtures.createConfirmPaymentBody,+ data,+ "no_three_ds",+ "automatic",+ globalState+ );++ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });+ });++ context("Duplicate Refund ID", () => {+ let shouldContinue = true; // variable that will be used to skip tests if a previous test fails++ beforeEach(function () {+ if (!shouldContinue) {+ this.skip();+ }+ });++ it("Create new refund", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["PartialRefund"];++ cy.refundCallTest(fixtures.refundBody, data, globalState);+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("Sync refund", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["SyncRefund"];++ cy.syncRefundCallTest(data, globalState);+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("Create a refund with a duplicate refund ID", () => {+ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["DuplicateRefundID"];++ data.Request.refund_id = globalState.get("refundId");++ cy.refundCallTest(fixtures.refundBody, data, globalState);+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });+ });++ context("Duplicate Customer ID", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ it("Create new customer", () => {+ cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);+ });++ it("Create a customer with a duplicate customer ID", () => {+ const customerData = fixtures.customerCreateBody;+ customerData.customer_id = globalState.get("customerId");++ cy.createCustomerCallTest(customerData, globalState);+ });+ });});diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 77f94cf30f..fc25220b80 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -888,25 +888,40 @@ Cypress.Commands.add("api-key": globalState.get("apiKey"),},body: customerCreateBody,+ failOnStatusCode: false,}).then((response) => {- globalState.set("customerId", response.body.customer_id);logRequestId(response.headers["x-request-id"]);cy.wrap(response).then(() => {- expect(response.body.customer_id, "customer_id").to.not.be.empty;- expect(customerCreateBody.email, "email").to.equal(response.body.email);- expect(customerCreateBody.name, "name").to.equal(response.body.name);- expect(customerCreateBody.phone, "phone").to.equal(response.body.phone);- expect(customerCreateBody.metadata, "metadata").to.deep.equal(- response.body.metadata- );- expect(customerCreateBody.address, "address").to.deep.equal(- response.body.address- );- expect(- customerCreateBody.phone_country_code,- "phone_country_code"- ).to.equal(response.body.phone_country_code);+ if (response.status === 200) {+ globalState.set("customerId", response.body.customer_id);++ expect(response.body.customer_id, "customer_id").to.not.be.empty;+ expect(customerCreateBody.email, "email").to.equal(+ response.body.email+ );+ expect(customerCreateBody.name, "name").to.equal(response.body.name);+ expect(customerCreateBody.phone, "phone").to.equal(+ response.body.phone+ );+ expect(customerCreateBody.metadata, "metadata").to.deep.equal(+ response.body.metadata+ );+ expect(customerCreateBody.address, "address").to.deep.equal(+ response.body.address+ );+ expect(+ customerCreateBody.phone_country_code,+ "phone_country_code"+ ).to.equal(response.body.phone_country_code);+ } else if (response.status === 400) {+ if (response.body.error.message.includes("already exists")) {+ expect(response.body.error.code).to.equal("IR_12");+ expect(response.body.error.message).to.equal(+ "Customer with the given `customer_id` already exists"+ );+ }+ }});});}@@ -2351,7 +2366,9 @@ Cypress.Commands.add("refundCallTest", (requestBody, data, globalState) => {// we only need this to set the delay. We don't need the return valueexecConfig(validateConfig(configs));- requestBody.amount = reqData.amount;+ for (const key in reqData) {+ requestBody[key] = reqData[key];+ }requestBody.payment_id = payment_id;cy.request({