From 7b0dbee6d25395c080404a60779b9064a923838a Mon Sep 17 00:00:00 2001 From: PiX <69745008+pixincreate@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:22:23 +0530 Subject: [PATCH] refactor: move error_code and error_message validations to a separate 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` --- cypress-tests/cypress/support/commands.js | 37 ++++++++--------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js index 8e0cd7d40101..4c4914161cf5 100644 --- a/cypress-tests/cypress/support/commands.js +++ b/cypress-tests/cypress/support/commands.js @@ -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) => { @@ -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); } @@ -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") { @@ -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": @@ -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" || @@ -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") { @@ -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") {