Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Cypress): Add response handler for Connector Testing #4624

Merged
merged 19 commits into from May 21, 2024

Conversation

Sakilmostak
Copy link
Contributor

@Sakilmostak Sakilmostak commented May 10, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

For testing scenarios, response were hardcoded rather than being specific to the connectors and their flows. This resulted in panic when multiple cases arrives for a same flow. This have been removed by adding configs specific to connectors to test them.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

Tested through Cypress
Screenshot 2024-05-14 at 7 36 14 PM

Stripe
Screenshot 2024-05-17 at 1 20 15 PM

Cybersource
Screenshot 2024-05-17 at 2 00 06 PM

Bankofamerica
Screenshot 2024-05-17 at 1 51 05 PM

Adyen
Screenshot 2024-05-17 at 3 24 41 PM

Paypal
Screenshot 2024-05-20 at 12 01 50 AM

Bluesnap
Screenshot 2024-05-17 at 3 52 14 PM

Note: Paypal,Bluesnap 3ds is not handled so the tests are failing. Adyen has status issue that we will handle it in different PR.

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@Sakilmostak Sakilmostak added C-feature Category: Feature request or enhancement C-test Category: Tests labels May 10, 2024
@Sakilmostak Sakilmostak self-assigned this May 10, 2024
@Sakilmostak Sakilmostak requested a review from a team as a code owner May 10, 2024 13:25
@Gnanasundari24 Gnanasundari24 requested review from a team as code owners May 16, 2024 08:19
@Sakilmostak Sakilmostak removed the request for review from a team May 20, 2024 06:53
body: requestBody,
}).then((response) => {
logRequestId(response.headers['x-request-id']);

console.log(response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the logs.

} else {
for(const key in res_data.body) {
expect(res_data.body[key]).to.equal(response.body[key]);
} } else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you format this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be linted by the corresponding PR raised by @pixincreate

body: requestBody,
}).then((response) => {
logRequestId(response.headers['x-request-id']);

console.log(response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this log

}).then((response) => {
logRequestId(response.headers['x-request-id']);

console.log(response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this log

body: requestBody
}).then((response) => {
logRequestId(response.headers['x-request-id']);

console.log(response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here. logs are for debug purpose, lets not have them in the framework

body: confirmBody,
}).then((response) => {
logRequestId(response.headers['x-request-id']);
console.log(response);

expect(res_data.status).to.equal(response.status);
expect(response.headers["content-type"]).to.include("application/json");
globalState.set("paymentID", paymentIntentID);
if (response.body.capture_method === "automatic") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you check on status code whether it is 2xx or 4xx, instead of checking response fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the status is being picked based on flow and connector from the configs, if it will always expect the respective http code for the test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that is correct but here, can we have if condition on status 2xx, and 4xx for better readability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you resolve this comment?

Comment on lines 171 to 173
expect(request.amount).to.equal(response.body.amount);
expect(null).to.equal(response.body.amount_received);
expect(request.amount).to.equal(response.body.amount_capturable);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sakilmostak aren't we expecting all assertions from connector config?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we discussed, revert this change, we have to combine all such common assertions into one file and for every test case, we should execute these assertions

});

function should_continue_further(res_data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is repetitive, can we have this in utils.js?!?

let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"]["No3DSManualCapture"];
let req_data = data["Request"];
let res_data = data["Response"];
console.log("det -> " + data.card);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the logs.

let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Capture"];
let req_data = data["Request"];
let res_data = data["Response"];
console.log("det -> " + data.card);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here.

let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"]["No3DSManualCapture"];
let req_data = data["Request"];
let res_data = data["Response"];
console.log("det -> " + data.card);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here.

let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Capture"];
let req_data = data["Request"];
let res_data = data["Response"];
console.log("det -> " + data.card);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prasunna09, You added these log lines, and they are present in all your initial commits. Removing them will take a significant amount of time. We'll address this issue later. For now, could you please approve this so we can proceed with the other changes? We are currently blocked by this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this can be taken up in separate pr

Comment on lines 159 to 161
if(response.status === "200"){

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

if(response.status === "200"){
globalState.set("clientSecret", clientSecret);
globalState.set("paymentID", response.body.payment_id);
cy.log(clientSecret);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this log if not needed

body: confirmBody,
}).then((response) => {
logRequestId(response.headers['x-request-id']);
console.log(response);

expect(res_data.status).to.equal(response.status);
expect(response.headers["content-type"]).to.include("application/json");
globalState.set("paymentID", paymentIntentID);
if (response.body.capture_method === "automatic") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you resolve this comment?

expect(response.body.amount).to.equal(refund_amount);
expect(response.body.payment_id).to.equal(payment_id);

if(response.body.status !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we having this condition? instead we could have response.body.status === "success" | "pending" right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status was being used to check whether the response was for 2xx, checking specifically for success and pending status would fail for 2xx which failed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has been update to check based on http code

expect(response.headers["content-type"]).to.include("application/json");
expect(response.body).to.have.property("mandate_id");
globalState.set("mandateId", response.body.mandate_id);
globalState.set("paymentID", response.body.payment_id);

if (response.body.capture_method === "automatic") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. can we have if statement with http status 2xx or 4xx condition for better readability

let data = getConnectorDetails(globalState.get("connectorId"))["card_pm"]["Capture"];
let req_data = data["Request"];
let res_data = data["Response"];
console.log("det -> " + data.card);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this can be taken up in separate pr

let req_data = data["Request"];
let res_data = data["Response"];
cy.createPaymentIntentTest(createPaymentBody, req_data, res_data, "no_three_ds", "manual", globalState);
if(should_continue) should_continue = utils.hould_continue_further(res_data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(should_continue) should_continue = utils.hould_continue_further(res_data);
if(should_continue) should_continue = utils.should_continue_further(res_data);

@@ -1,10 +1,10 @@
{
"amount": 6540,
"amount": 6500,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

// expect(response.body.amount_capturable).to.equal(0);
expect(response.body.amount_received).to.be.oneOf([0, null]);
expect(response.body.status).to.equal("cancelled");
if(response.body.payment_id !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we have a condition on payment_id? why not on status code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has been converted to status code

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 21, 2024
Merged via the queue into main with commit 2e79ee0 May 21, 2024
10 checks passed
@Gnanasundari24 Gnanasundari24 deleted the cypress_framework_enhancement branch May 21, 2024 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: Feature request or enhancement C-test Category: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants