feat(cypress): valdiate error_code and error_message and make it visible in reports (#6913)

This commit is contained in:
Pa1NarK
2024-12-23 23:30:21 +05:30
committed by GitHub
parent 44653850f0
commit 46b2bfe48a

View File

@ -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) => {
@ -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);
}
@ -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)
@ -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 {
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;
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 authentication type ${response.body.authentication_type}`
);
}
}
} else {
defaultErrorHandler(response, resData);
@ -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"
@ -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"
@ -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)
@ -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)