Skip to content

Commit

Permalink
feat(cypress-test): include worldpay's request / response structure f…
Browse files Browse the repository at this point in the history
…or test suite (#6420)
  • Loading branch information
kashif-m authored Oct 30, 2024
1 parent d697def commit 8372389
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 40 deletions.
4 changes: 2 additions & 2 deletions cypress-tests/cypress/e2e/PaymentTest/00006-VoidPayment.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("Card - NoThreeDS Manual payment flow test", () => {

it("void-call-test", () => {
let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"][
"Void"
"VoidAfterConfirm"
];
let req_data = data["Request"];
let res_data = data["Response"];
Expand Down Expand Up @@ -178,7 +178,7 @@ describe("Card - NoThreeDS Manual payment flow test", () => {
it("void-call-test", () => {
let data = getConnectorDetails(globalState.get("connectorId"))[
"card_pm"
]["Void"];
]["VoidAfterConfirm"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.voidCallTest(fixtures.voidBody, req_data, res_data, globalState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ describe("Card - SaveCard payment flow test", () => {
"automatic",
globalState
);
if (should_continue)
should_continue = utils.should_continue_further(res_data);
if (should_continue) {
// Don't continue if payment status is processing during auto capture
// Payment data is tokenized only after payment is successful
let notProcessing = res_data?.body?.status != "processing";
should_continue =
notProcessing && utils.should_continue_further(res_data);
}
});

it("retrieve-payment-call-test", () => {
Expand Down
22 changes: 11 additions & 11 deletions cypress-tests/cypress/e2e/PaymentTest/00020-Variations.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ describe("Corner cases", () => {
});

it("Capture call", () => {
let data = getConnectorDetails(globalState.get("commons"))["card_pm"][
let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"][
"CaptureCapturedAmount"
];

Expand Down Expand Up @@ -396,7 +396,7 @@ describe("Corner cases", () => {
});

it("Confirm call", () => {
let data = getConnectorDetails(globalState.get("commons"))["card_pm"][
let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"][
"ConfirmSuccessfulPayment"
];
let req_data = data["Request"];
Expand Down Expand Up @@ -460,12 +460,12 @@ describe("Corner cases", () => {
});

it("Void call", () => {
// `commons` here is intentionally used as we need to pass `ResponseCustom`
let data = getConnectorDetails(globalState.get("commons"))["card_pm"][
let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"][
"Void"
];
let commonData = getConnectorDetails(globalState.get("commons"))["card_pm"]["Void"];
let req_data = data["Request"];
let res_data = data["ResponseCustom"];
let res_data = utils.getConnectorFlowDetails(data, commonData, "ResponseCustom");
cy.voidCallTest(fixtures.voidBody, req_data, res_data, globalState);

if (should_continue)
Expand Down Expand Up @@ -592,12 +592,12 @@ describe("Corner cases", () => {
});

it("Refund call", () => {
// `commons` here is intentionally used as we need to pass `ResponseCustom`
let data = getConnectorDetails(globalState.get("commons"))["card_pm"][
let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"][
"Refund"
];
let commonData = getConnectorDetails(globalState.get("commons"))["card_pm"]["Refund"];
let req_data = data["Request"];
let res_data = data["ResponseCustom"];
let res_data = utils.getConnectorFlowDetails(data, commonData, "ResponseCustom");
cy.refundCallTest(
fixtures.refundBody,
req_data,
Expand Down Expand Up @@ -655,12 +655,12 @@ describe("Corner cases", () => {
});

it("Refund call", () => {
// `commons` here is intentionally used as we need to pass `ResponseCustom`
let data = getConnectorDetails(globalState.get("commons"))["card_pm"][
let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"][
"Refund"
];
let commonData = getConnectorDetails(globalState.get("commons"))["card_pm"]["Refund"];
let req_data = data["Request"];
let res_data = data["ResponseCustom"];
let res_data = utils.getConnectorFlowDetails(data, commonData, "ResponseCustom");
cy.refundCallTest(
fixtures.refundBody,
req_data,
Expand Down
21 changes: 21 additions & 0 deletions cypress-tests/cypress/e2e/PaymentUtils/Commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,27 @@ export const connectorDetails = {
},
},
}),
VoidAfterConfirm: getCustomExchange({
Request: {},
Response: {
status: 200,
body: {
status: "cancelled",
capture_method: "manual",
},
},
ResponseCustom: {
status: 400,
body: {
error: {
type: "invalid_request",
message:
"You cannot cancel this payment because it has status succeeded",
code: "IR_16",
},
},
},
}),
Refund: getCustomExchange({
Request: {
payment_method: "card",
Expand Down
23 changes: 0 additions & 23 deletions cypress-tests/cypress/e2e/PaymentUtils/Paybox.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,29 +401,6 @@ export const connectorDetails = {
},
},
},
CaptureCapturedAmount: {
Request: {
Request: {
payment_method: "card",
payment_method_data: {
card: successfulNo3DSCardDetails,
},
currency: "EUR",
customer_acceptance: null,
},
},
Response: {
status: 400,
body: {
error: {
type: "invalid_request",
message:
"This Payment could not be captured because it has a payment.status of succeeded. The expected state is requires_capture, partially_captured_and_capturable, processing",
code: "IR_14",
},
},
},
},
ConfirmSuccessfulPayment: {
Request: {
payment_method: "card",
Expand Down
7 changes: 7 additions & 0 deletions cypress-tests/cypress/e2e/PaymentUtils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { connectorDetails as stripeConnectorDetails } from "./Stripe.js";
import { connectorDetails as trustpayConnectorDetails } from "./Trustpay.js";
import { connectorDetails as wellsfargoConnectorDetails } from "./WellsFargo.js";
import { connectorDetails as fiuuConnectorDetails } from "./Fiuu.js";
import { connectorDetails as worldpayConnectorDetails } from "./WorldPay.js";

const connectorDetails = {
adyen: adyenConnectorDetails,
Expand All @@ -39,13 +40,19 @@ const connectorDetails = {
datatrans: datatransConnectorDetails,
wellsfargo: wellsfargoConnectorDetails,
fiuu: fiuuConnectorDetails,
worldpay: worldpayConnectorDetails,
};

export default function getConnectorDetails(connectorId) {
let x = mergeDetails(connectorId);
return x;
}

export function getConnectorFlowDetails(connectorData, commonData, key) {
let data = connectorData[key] === undefined ? commonData[key] : connectorData[key];
return data;
}

function mergeDetails(connectorId) {
const connectorData = getValueByKey(connectorDetails, connectorId);
const fallbackData = getValueByKey(connectorDetails, "commons");
Expand Down
Loading

0 comments on commit 8372389

Please sign in to comment.