Skip to content

Commit

Permalink
feat(cypress): valdiate error_code and error_message and make it …
Browse files Browse the repository at this point in the history
…visible in `reports` (#6913)
  • Loading branch information
pixincreate authored Dec 23, 2024
1 parent d4b3dbc commit 97c81ff
Showing 1 changed file with 76 additions and 52 deletions.
128 changes: 76 additions & 52 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 @@ -1113,6 +1120,8 @@ Cypress.Commands.add(
).to.be.null;
expect(response.body.connector_mandate_id, "connector_mandate_id").to.be
.null;

validateErrorMessage(response, resData);
} else {
defaultErrorHandler(response, resData);
}
Expand Down Expand Up @@ -1319,6 +1328,8 @@ Cypress.Commands.add(
expect(response.body.profile_id, "profile_id").to.equal(profileId).and
.to.not.be.null;

validateErrorMessage(response, resData);

if (response.body.capture_method === "automatic") {
if (response.body.authentication_type === "three_ds") {
expect(response.body)
Expand Down Expand Up @@ -1419,64 +1430,68 @@ Cypress.Commands.add(
globalState.set("connectorId", response.body.connector);
globalState.set("paymentMethodType", confirmBody.payment_method_type);

switch (response.body.authentication_type) {
case "three_ds":
if (
response.body.capture_method === "automatic" ||
response.body.capture_method === "manual"
) {
if (response.body.status !== "failed") {
// we get many statuses here, hence this verification
if (
connectorId === "adyen" &&
response.body.payment_method_type === "blik"
) {
expect(response.body)
.to.have.property("next_action")
.to.have.property("type")
.to.equal("wait_screen_information");
} else {
expect(response.body)
.to.have.property("next_action")
.to.have.property("redirect_to_url");
globalState.set(
"nextActionUrl",
response.body.next_action.redirect_to_url
if (response.status === 200) {
validateErrorMessage(response, resData);

switch (response.body.authentication_type) {
case "three_ds":
if (
response.body.capture_method === "automatic" ||
response.body.capture_method === "manual"
) {
if (response.body.status !== "failed") {
// we get many statuses here, hence this verification
if (
connectorId === "adyen" &&
response.body.payment_method_type === "blik"
) {
expect(response.body)
.to.have.property("next_action")
.to.have.property("type")
.to.equal("wait_screen_information");
} else {
expect(response.body)
.to.have.property("next_action")
.to.have.property("redirect_to_url");
globalState.set(
"nextActionUrl",
response.body.next_action.redirect_to_url
);
}
} else if (response.body.status === "failed") {
expect(response.body.error_code).to.equal(
resData.body.error_code
);
}
} else if (response.body.status === "failed") {
expect(response.body.error_code).to.equal(
resData.body.error_code
} else {
throw new Error(
`Invalid capture method ${response.body.capture_method}`
);
}
} else {
throw new Error(
`Invalid capture method ${response.body.capture_method}`
);
}
break;
case "no_three_ds":
if (
response.body.capture_method === "automatic" ||
response.body.capture_method === "manual"
) {
expect(response.body)
.to.have.property("next_action")
.to.have.property("redirect_to_url");
globalState.set(
"nextActionUrl",
response.body.next_action.redirect_to_url
);
} else {
break;
case "no_three_ds":
if (
response.body.capture_method === "automatic" ||
response.body.capture_method === "manual"
) {
expect(response.body)
.to.have.property("next_action")
.to.have.property("redirect_to_url");
globalState.set(
"nextActionUrl",
response.body.next_action.redirect_to_url
);
} else {
throw new Error(
`Invalid capture method ${response.body.capture_method}`
);
}
break;
default:
throw new Error(
`Invalid capture method ${response.body.capture_method}`
`Invalid authentication type ${response.body.authentication_type}`
);
}
break;
default:
throw new Error(
`Invalid authentication type ${response.body.authentication_type}`
);
}
}
} else {
defaultErrorHandler(response, resData);
Expand Down Expand Up @@ -1521,6 +1536,9 @@ Cypress.Commands.add(
expect(response.headers["content-type"]).to.include("application/json");
if (response.status === 200) {
globalState.set("paymentID", paymentIntentID);

validateErrorMessage(response, resData);

if (
response.body.capture_method === "automatic" ||
response.body.capture_method === "manual"
Expand Down Expand Up @@ -1601,6 +1619,8 @@ Cypress.Commands.add(
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
if (response.status === 200) {
validateErrorMessage(response, resData);

if (
response.body.capture_method === "automatic" ||
response.body.capture_method === "manual"
Expand Down Expand Up @@ -1698,6 +1718,8 @@ Cypress.Commands.add(
expect(response.body.profile_id, "profile_id").to.not.be.null;
expect(response.body).to.have.property("status");

validateErrorMessage(response, resData);

if (response.body.capture_method === "automatic") {
if (response.body.authentication_type === "three_ds") {
expect(response.body)
Expand Down Expand Up @@ -1819,6 +1841,8 @@ 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;

validateErrorMessage(response, resData);

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

0 comments on commit 97c81ff

Please sign in to comment.