Skip to content

Commit

Permalink
ci(cypress): add test cases for duplicate requests (#7220)
Browse files Browse the repository at this point in the history
  • Loading branch information
likhinbopanna authored Feb 12, 2025
1 parent c41bfc9 commit 7f66035
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 16 deletions.
38 changes: 38 additions & 0 deletions cypress-tests/cypress/e2e/configs/Payment/Commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
113 changes: 113 additions & 0 deletions cypress-tests/cypress/e2e/spec/Payment/00022-Variations.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
49 changes: 33 additions & 16 deletions cypress-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}
});
});
}
Expand Down Expand Up @@ -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 value
execConfig(validateConfig(configs));

requestBody.amount = reqData.amount;
for (const key in reqData) {
requestBody[key] = reqData[key];
}
requestBody.payment_id = payment_id;

cy.request({
Expand Down

0 comments on commit 7f66035

Please sign in to comment.