feat(Cypress): Add routing test (#4768)

This commit is contained in:
Sakil Mostak
2024-06-07 15:24:26 +05:30
committed by GitHub
parent 13fa7d5c56
commit 39d46fd015
10 changed files with 420 additions and 2 deletions

View File

@ -63,6 +63,7 @@ Cypress.Commands.add(
logRequestId(response.headers["x-request-id"]);
// Handle the response as needed
globalState.set("profileID", response.body.default_profile);
globalState.set("publishableKey", response.body.publishable_key);
});
},
@ -174,6 +175,51 @@ Cypress.Commands.add(
},
);
Cypress.Commands.add(
"createConnectorWithNameCallTest",
(createConnectorBody, connector_name, connector_type, globalState) => {
const merchantId = globalState.get("merchantId");
createConnectorBody.connector_name = connector_name;
createConnectorBody.connector_type = connector_type;
// readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature
// it is best to use then() to handle the response within the same block of code
cy.readFile(globalState.get("connectorAuthFilePath")).then(
(jsonContent) => {
const authDetails = getValueByKey(
JSON.stringify(jsonContent),
connector_name,
);
createConnectorBody.connector_account_details = authDetails;
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"api-key": globalState.get("adminApiKey"),
},
body: createConnectorBody,
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
if (response.status === 200) {
globalState.set(
`${connector_name}_mc_id`,
response.body.merchant_connector_id,
);
} else {
cy.task(
"cli_log",
"response status -> " + JSON.stringify(response.status),
);
}
});
},
);
},
);
function getValueByKey(jsonObject, key) {
const data =
typeof jsonObject === "string" ? JSON.parse(jsonObject) : jsonObject;
@ -1174,3 +1220,110 @@ Cypress.Commands.add("retrievePayoutCallTest", (globalState) => {
expect(response.body.amount).to.equal(globalState.get("payoutAmount"));
});
});
Cypress.Commands.add(
"addRoutingConfig",
(routingBody, req_data, res_data, type, data, globalState) => {
for (const key in req_data) {
routingBody[key] = req_data[key];
}
routingBody.profile_id = globalState.get("profileID");
routingBody.algorithm.type = type;
routingBody.algorithm.data = data;
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/routing`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
body: routingBody,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(res_data.status).to.equal(response.status);
expect(response.headers["content-type"]).to.include("application/json");
if (response.status === 200) {
expect(response.body).to.have.property("id");
globalState.set("routingConfigId", response.body.id);
for (const key in res_data.body) {
expect(res_data.body[key]).to.equal(response.body[key]);
}
} else {
expect(response.body).to.have.property("error");
for (const key in res_data.body.error) {
expect(res_data.body.error[key]).to.equal(response.body.error[key]);
}
}
});
},
);
Cypress.Commands.add(
"activateRoutingConfig",
(req_data, res_data, globalState) => {
let routing_config_id = globalState.get("routingConfigId");
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/routing/${routing_config_id}/activate`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(res_data.status).to.equal(response.status);
expect(response.headers["content-type"]).to.include("application/json");
if (response.status === 200) {
expect(response.body.id).to.equal(routing_config_id);
for (const key in res_data.body) {
expect(res_data.body[key]).to.equal(response.body[key]);
}
} else {
expect(response.body).to.have.property("error");
for (const key in res_data.body.error) {
expect(res_data.body.error[key]).to.equal(response.body.error[key]);
}
}
});
},
);
Cypress.Commands.add(
"retrieveRoutingConfig",
(req_data, res_data, globalState) => {
let routing_config_id = globalState.get("routingConfigId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(res_data.status).to.equal(response.status);
expect(response.headers["content-type"]).to.include("application/json");
if (response.status === 200) {
expect(response.body.id).to.equal(routing_config_id);
for (const key in res_data.body) {
expect(res_data.body[key]).to.equal(response.body[key]);
}
} else {
expect(response.body).to.have.property("error");
for (const key in res_data.body.error) {
expect(res_data.body.error[key]).to.equal(response.body.error[key]);
}
}
});
},
);