Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cypress-test): include worldpay's request / response structure for test suite #6420

Merged
merged 6 commits into from
Oct 30, 2024
Merged
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",
},
},
},
}),
kashif-m marked this conversation as resolved.
Show resolved Hide resolved
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;
}

Comment on lines +51 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we could do a deep merge of commons.js and <connector>.js in a safer way that does not overrides the existing configs from <connector>.js, this change would never be needed.

as discussed, deep merge will for sure add overhead, but would reduce complexity is what i feel.

this should also work, but i do think this will have a very limited scope of use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does have a very limited scope as of now, we can remove this once we introduce custom deep merge (merge everything except Response). But we can let it be for now, since it's out of scope of this PR

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