Skip to content

Commit

Permalink
refactor: move error_code and error_message validations to a separate…
Browse files Browse the repository at this point in the history
… functino for reusing

functions added in `commands.js` will be moved to a separate folder file
and possibly take out some of the functions from `Utils.js`
  • Loading branch information
pixincreate committed Dec 23, 2024
1 parent 64aacfc commit 7b0dbee
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions cypress-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ function logRequestId(xRequestId) {
}
}

function validateErrorMessage(response, resData) {
if (resData.body.status !== "failed") {
expect(response.body.error_message).to.be.null;
expect(response.body.error_code).to.be.null;
}
}

Cypress.Commands.add(
"merchantCreateCallTest",
(merchantCreateBody, globalState) => {
Expand Down Expand Up @@ -1114,10 +1121,7 @@ Cypress.Commands.add(
expect(response.body.connector_mandate_id, "connector_mandate_id").to.be
.null;

if (resData.body.status !== "failed") {
expect(response.body.error_message).to.be.null;
expect(response.body.error_code).to.be.null;
}
validateErrorMessage(response, resData);
} else {
defaultErrorHandler(response, resData);
}
Expand Down Expand Up @@ -1324,10 +1328,7 @@ Cypress.Commands.add(
expect(response.body.profile_id, "profile_id").to.equal(profileId).and
.to.not.be.null;

if (resData.body.status !== "failed") {
expect(response.body.error_message).to.be.null;
expect(response.body.error_code).to.be.null;
}
validateErrorMessage(response, resData);

if (response.body.capture_method === "automatic") {
if (response.body.authentication_type === "three_ds") {
Expand Down Expand Up @@ -1430,10 +1431,7 @@ Cypress.Commands.add(
globalState.set("paymentMethodType", confirmBody.payment_method_type);

if (response.status === 200) {
if (resData.body.status !== "failed") {
expect(response.body.error_message).to.be.null;
expect(response.body.error_code).to.be.null;
}
validateErrorMessage(response, resData);

switch (response.body.authentication_type) {
case "three_ds":
Expand Down Expand Up @@ -1539,10 +1537,7 @@ Cypress.Commands.add(
if (response.status === 200) {
globalState.set("paymentID", paymentIntentID);

if (resData.body.status !== "failed") {
expect(response.body.error_message).to.be.null;
expect(response.body.error_code).to.be.null;
}
validateErrorMessage(response, resData);

if (
response.body.capture_method === "automatic" ||
Expand Down Expand Up @@ -1726,10 +1721,7 @@ Cypress.Commands.add(
expect(response.body.profile_id, "profile_id").to.not.be.null;
expect(response.body).to.have.property("status");

if (resData.body.status !== "failed") {
expect(response.body.error_message).to.be.null;
expect(response.body.error_code).to.be.null;
}
validateErrorMessage(response, resData);

if (response.body.capture_method === "automatic") {
if (response.body.authentication_type === "three_ds") {
Expand Down Expand Up @@ -1852,10 +1844,7 @@ Cypress.Commands.add(
expect(response.body.profile_id, "profile_id").to.not.be.null;
expect(response.body.payment_token, "payment_token").to.not.be.null;

if (resData.body.status !== "failed") {
expect(response.body.error_message).to.be.null;
expect(response.body.error_code).to.be.null;
}
validateErrorMessage(response, resData);

if (response.body.capture_method === "automatic") {
if (response.body.authentication_type === "three_ds") {
Expand Down

0 comments on commit 7b0dbee

Please sign in to comment.