Skip to content

Commit

Permalink
ci(cypress): add testcases for nti based mit flow (#6567)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShankarSinghC authored Nov 26, 2024
1 parent 9baa1ef commit ea81432
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 0 deletions.
221 changes: 221 additions & 0 deletions cypress-tests/cypress/e2e/PaymentTest/00020-MandatesUsingNTID.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
import * as fixtures from "../../fixtures/imports";
import State from "../../utils/State";
import getConnectorDetails, * as utils from "../PaymentUtils/Utils";

let globalState;
let connector;

describe("Card - Mandates using Network Transaction Id flow test", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
connector = globalState.get("connectorId");
});
});

afterEach("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});

context(
"Card - NoThreeDS Create and Confirm Automatic MIT payment flow test",
() => {
let should_continue = true;

beforeEach(function () {
if (!should_continue || connector !== "cybersource") {
this.skip();
}
});

it("Confirm No 3DS MIT", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
7000,
true,
"automatic",
globalState
);
});
}
);

context(
"Card - NoThreeDS Create and Confirm Manual MIT payment flow test",
() => {
let should_continue = true;

beforeEach(function () {
if (!should_continue || connector !== "cybersource") {
this.skip();
}
});

it("Confirm No 3DS MIT", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
7000,
true,
"manual",
globalState
);
});
}
);

context(
"Card - NoThreeDS Create and Confirm Automatic multiple MITs payment flow test",
() => {
let should_continue = true;

beforeEach(function () {
if (!should_continue || connector !== "cybersource") {
this.skip();
}
});

it("Confirm No 3DS MIT", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
7000,
true,
"automatic",
globalState
);
});
it("Confirm No 3DS MIT", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
7000,
true,
"automatic",
globalState
);
});
}
);

context(
"Card - NoThreeDS Create and Confirm Manual multiple MITs payment flow test",
() => {
let should_continue = true;

beforeEach(function () {
if (!should_continue || connector !== "cybersource") {
this.skip();
}
});

it("Confirm No 3DS MIT 1", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
6500,
true,
"manual",
globalState
);
});

it("mit-capture-call-test", () => {
let data = getConnectorDetails(globalState.get("connectorId"))[
"card_pm"
]["Capture"];
let req_data = data["Request"];
let res_data = data["Response"];

cy.captureCallTest(
fixtures.captureBody,
req_data,
res_data,
6500,
globalState
);
if (should_continue)
should_continue = utils.should_continue_further(res_data);
});

it("Confirm No 3DS MIT 2", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
6500,
true,
"manual",
globalState
);
});

it("mit-capture-call-test", () => {
let data = getConnectorDetails(globalState.get("connectorId"))[
"card_pm"
]["Capture"];
let req_data = data["Request"];
let res_data = data["Response"];

cy.captureCallTest(
fixtures.captureBody,
req_data,
res_data,
6500,
globalState
);
if (should_continue)
should_continue = utils.should_continue_further(res_data);
});
}
);

context(
"Card - ThreeDS Create and Confirm Automatic multiple MITs payment flow test",
() => {
let should_continue = true;

beforeEach(function () {
if (!should_continue || connector !== "cybersource") {
this.skip();
}
});

it("Confirm No 3DS MIT", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
7000,
true,
"automatic",
globalState
);
});
it("Confirm No 3DS MIT", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
7000,
true,
"automatic",
globalState
);
});
}
);

context(
"Card - ThreeDS Create and Confirm Manual multiple MITs payment flow",
() => {
let should_continue = true;

beforeEach(function () {
if (!should_continue || connector !== "cybersource") {
this.skip();
}
});

it("Confirm No 3DS MIT", () => {
cy.mitUsingNTID(
fixtures.ntidConfirmBody,
7000,
true,
"automatic",
globalState
);
});
}
);
});
49 changes: 49 additions & 0 deletions cypress-tests/cypress/fixtures/create-ntid-mit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"amount": 999,
"currency": "USD",
"confirm": true,
"payment_method": "card",
"return_url": "https://hyperswitch.io",
"email": "[email protected]",
"recurring_details": {
"type": "network_transaction_id_and_card_details",
"data": {
"card_number": "4242424242424242",
"card_exp_month": "11",
"card_exp_year": "2024",
"card_holder_name": "joseph Doe",
"network_transaction_id": "MCC5ZRGMI0925"
}
},
"off_session": true,
"billing": {
"address": {
"first_name": "John",
"last_name": "Doe",
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US"
},
"phone": {
"number": "9123456789",
"country_code": "+91"
}
},
"browser_info": {
"ip_address": "129.0.0.1",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"language": "en-US",
"color_depth": 30,
"screen_height": 1117,
"screen_width": 1728,
"time_zone": -330,
"java_enabled": true,
"java_script_enabled": true
}
}

2 changes: 2 additions & 0 deletions cypress-tests/cypress/fixtures/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import updateBusinessProfile from "./update-business-profile.json";
import updateConnectorBody from "./update-connector-body.json";
import customerUpdateBody from "./update-customer-body.json";
import voidBody from "./void-payment-body.json";
import ntidConfirmBody from "./create-ntid-mit.json";

export {
apiKeyCreateBody,
Expand All @@ -44,6 +45,7 @@ export {
merchantCreateBody,
merchantUpdateBody,
mitConfirmBody,
ntidConfirmBody,
pmIdConfirmBody,
refundBody,
routingConfigBody,
Expand Down
75 changes: 75 additions & 0 deletions cypress-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,81 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add(
"mitUsingNTID",
(requestBody, amount, confirm, capture_method, globalState) => {

requestBody.amount = amount;
requestBody.confirm = confirm;
requestBody.capture_method = capture_method;

if (globalState.get("connectorId") !== "cybersource") {
return;
}

const apiKey = globalState.get("apiKey");
const baseUrl = globalState.get("baseUrl");
const url = `${baseUrl}/payments`;

cy.request({
method: "POST",
url: url,
headers: {
"Content-Type": "application/json",
"api-key": apiKey,
},
failOnStatusCode: false,
body: requestBody,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);

if (response.status === 200) {
expect(response.headers["content-type"]).to.include("application/json");

globalState.set("paymentID", response.body.payment_id);

if (response.body.capture_method === "automatic") {
if (response.body.authentication_type === "three_ds") {
expect(response.body)
.to.have.property("next_action")
.to.have.property("redirect_to_url");
const nextActionUrl = response.body.next_action.redirect_to_url;
cy.log(nextActionUrl);
} else if (response.body.authentication_type === "no_three_ds") {
expect(response.body.status).to.equal("succeeded");
} else {
throw new Error(
`Invalid authentication type ${response.body.authentication_type}`
);
}
} else if (response.body.capture_method === "manual") {
if (response.body.authentication_type === "three_ds") {
expect(response.body)
.to.have.property("next_action")
.to.have.property("redirect_to_url");
const nextActionUrl = response.body.next_action.redirect_to_url;
cy.log(nextActionUrl);
} else if (response.body.authentication_type === "no_three_ds") {
expect(response.body.status).to.equal("requires_capture");
} else {
throw new Error(
`Invalid authentication type ${response.body.authentication_type}`
);
}
} else {
throw new Error(
`Invalid capture method ${response.body.capture_method}`
);
}
} else {
throw new Error(
`Error Response: ${response.status}\n${response.body.error.message}\n${response.body.error.code}`
);
}
});
}
);

Cypress.Commands.add("listMandateCallTest", (globalState) => {
const customerId = globalState.get("customerId");
cy.request({
Expand Down

0 comments on commit ea81432

Please sign in to comment.