feat(cypress): add core flow tests (#5546)

This commit is contained in:
Pa1NarK
2024-08-07 14:02:43 +05:30
committed by GitHub
parent 29c5f8a757
commit 7e545e36eb
7 changed files with 659 additions and 4 deletions

View File

@ -0,0 +1,187 @@
import * as fixtures from "../../fixtures/imports";
import State from "../../utils/State";
import { payment_methods_enabled } from "../PaymentUtils/Commons";
let globalState;
describe("Core flows", () => {
context("Merchant core flows", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
});
});
after("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});
it("merchant create call", () => {
cy.merchantCreateCallTest(fixtures.merchantCreateBody, globalState);
});
it("merchant retrieve call", () => {
cy.merchantRetrieveCall(globalState);
});
it("merchant list call", () => {
cy.merchantListCall(globalState);
});
it("merchant update call", () => {
cy.merchantUpdateCall(fixtures.merchantUpdateBody, globalState);
});
});
context("API key core flows", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
});
});
after("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});
it("API key create call", () => {
cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);
});
it("API key update call", () => {
cy.apiKeyUpdateCall(fixtures.apiKeyUpdateBody, globalState);
});
it("API key retrieve call", () => {
cy.apiKeyRetrieveCall(globalState);
});
it("API key list call", () => {
cy.apiKeyListCall(globalState);
});
});
context("Customer core flows", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
});
});
after("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});
it("Customer create call", () => {
cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
});
it("Customer list call", () => {
cy.customerListCall(globalState);
});
it("Customer retrieve call", () => {
cy.customerRetrieveCall(globalState);
});
it("Customer update call", () => {
cy.customerUpdateCall(fixtures.customerUpdateBody, globalState);
});
it("Ephemeral key generate call", () => {
cy.ephemeralGenerateCall(globalState);
});
});
context("Merchant Connector Account core flows", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
});
});
after("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});
context("Create Multiple Merchant Connector Accounts", () => {
it("1st Connector create call", () => {
// `globalState` can only be accessed in the `it` block
const connector_id = globalState.data.connectorId;
cy.createNamedConnectorCallTest(
"payment_processor",
fixtures.createConnectorBody,
payment_methods_enabled,
globalState,
connector_id,
"first_" + connector_id
);
});
it("2nd Connector create call", () => {
// `globalState` can only be accessed in the `it` block
const connector_id = globalState.data.connectorId;
cy.createNamedConnectorCallTest(
"payment_processor",
fixtures.createConnectorBody,
payment_methods_enabled,
globalState,
connector_id,
"second_" + connector_id
);
});
});
it("Connector create call", () => {
cy.createConnectorCallTest(
"payment_processor",
fixtures.createConnectorBody,
payment_methods_enabled,
globalState
);
});
it("Connector retrieve call", () => {
cy.connectorRetrieveCall(globalState);
});
it("Connector update call", () => {
cy.connectorUpdateCall(
"payment_processor",
fixtures.updateConnectorBody,
globalState
);
});
it("List connectors by MID", () => {
cy.connectorListByMid(globalState);
});
});
context("Delete calls", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
});
});
after("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});
it("Customer delete call", () => {
cy.customerDeleteCall(globalState);
});
it("API key delete call", () => {
cy.apiKeyDeleteCall(globalState);
});
it("Connector delete call", () => {
cy.connectorDeleteCall(globalState);
});
it("Merchant delete call", () => {
cy.merchantDeleteCall(globalState);
});
});
});

View File

@ -11,13 +11,18 @@ import createPayoutBody from "./create-payout-confirm-body.json";
import pmIdConfirmBody from "./create-pm-id-mit.json";
import listRefundCall from "./list-refund-call-body.json";
import merchantCreateBody from "./merchant-create-body.json";
import merchantUpdateBody from "./merchant-update-body.json";
import refundBody from "./refund-flow-body.json";
import routingConfigBody from "./routing-config-body.json";
import saveCardConfirmBody from "./save-card-confirm-body.json";
import apiKeyUpdateBody from "./update-api-key-body.json";
import updateConnectorBody from "./update-connector-body.json";
import customerUpdateBody from "./update-customer-body.json";
import voidBody from "./void-payment-body.json";
export {
apiKeyCreateBody,
apiKeyUpdateBody,
captureBody,
citConfirmBody,
confirmBody,
@ -26,12 +31,15 @@ export {
createPaymentBody,
createPayoutBody,
customerCreateBody,
customerUpdateBody,
listRefundCall,
merchantCreateBody,
merchantUpdateBody,
mitConfirmBody,
pmIdConfirmBody,
refundBody,
routingConfigBody,
saveCardConfirmBody,
updateConnectorBody,
voidBody,
};

View File

@ -0,0 +1,39 @@
{
"merchant_id": "merchant_id",
"merchant_name": "NewAge Retailer",
"locker_id": "m0010",
"merchant_details": {
"primary_contact_person": "joseph Test",
"primary_email": "josephTest@test.com",
"primary_phone": "veniam aute officia ullamco esse",
"secondary_contact_person": "joseph Test2",
"secondary_email": "josephTest2@test.com",
"secondary_phone": "proident adipisicing officia nulla",
"website": "www.example.com",
"about_business": "Online Retail with a wide selection of organic products for North America",
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US"
}
},
"return_url": "https://duck.com",
"webhook_details": {
"webhook_version": "1.0.1",
"webhook_username": "ekart_retail",
"webhook_password": "password_ekart@123",
"payment_created_enabled": true,
"payment_succeeded_enabled": true,
"payment_failed_enabled": true
},
"sub_merchants_enabled": false,
"parent_merchant_id": "xkkdf909012sdjki2dkh5sdf",
"metadata": {
"city": "NY",
"unit": "245"
}
}

View File

@ -0,0 +1,5 @@
{
"name": "Updated API Key",
"description": "My very awesome API key",
"expiration": null
}

View File

@ -0,0 +1,9 @@
{
"connector_label": "updated_connector_label",
"test_mode": true,
"disabled": false,
"metadata": {
"city": "LA",
"unit": "246"
}
}

View File

@ -0,0 +1,11 @@
{
"email": "JohnTest@test.com",
"name": "John Test",
"phone_country_code": "+65",
"phone": "888888888",
"description": "First customer",
"metadata": {
"city": "NY",
"unit": "245"
}
}

View File

@ -48,8 +48,8 @@ Cypress.Commands.add(
method: "POST",
url: `${globalState.get("baseUrl")}/accounts`,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
body: merchantCreateBody,
@ -58,6 +58,104 @@ Cypress.Commands.add(
// Handle the response as needed
globalState.set("publishableKey", response.body.publishable_key);
globalState.set("merchantDetails", response.body.merchant_details);
});
}
);
Cypress.Commands.add("merchantRetrieveCall", (globalState) => {
const merchant_id = globalState.get("merchantId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/accounts/${merchant_id}`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body.merchant_id).to.equal(merchant_id);
expect(response.body.amount).to.equal(globalState.get("paymentAmount"));
expect(response.body.payment_response_hash_key).to.not.be.empty;
expect(response.body.publishable_key).to.not.be.empty;
expect(response.body.default_profile).to.not.be.empty;
expect(response.body.organization_id).to.not.be.empty;
globalState.set("organizationId", response.body.organization_id);
});
});
Cypress.Commands.add("merchantDeleteCall", (globalState) => {
const merchant_id = globalState.get("merchantId");
cy.request({
method: "DELETE",
url: `${globalState.get("baseUrl")}/accounts/${merchant_id}`,
headers: {
Accept: "application/json",
"api-key": globalState.get("adminApiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.body.merchant_id).to.equal(merchant_id);
expect(response.body.deleted).to.equal(true);
});
});
Cypress.Commands.add("merchantListCall", (globalState) => {
const organization_id = globalState.get("organizationId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/accounts/list?organization_id=${organization_id}`,
headers: {
Accept: "application/json",
"api-key": globalState.get("adminApiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
for (const key in response.body) {
expect(response.body[key]).to.have.property("merchant_id").and.not.empty;
expect(response.body[key]).to.have.property("organization_id").and.not
.empty;
expect(response.body[key]).to.have.property("default_profile").and.not
.empty;
}
});
});
Cypress.Commands.add(
"merchantUpdateCall",
(merchantUpdateBody, globalState) => {
const merchant_id = globalState.get("merchantId");
const organization_id = globalState.get("organizationId");
const publishable_key = globalState.get("publishableKey");
const merchant_details = globalState.get("merchantDetails");
merchantUpdateBody.merchant_id = merchant_id;
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/accounts/${merchant_id}`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
body: merchantUpdateBody,
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body.merchant_id).to.equal(merchant_id);
expect(response.body.publishable_key).to.equal(publishable_key);
expect(response.body.organization_id).to.equal(organization_id);
expect(response.body.merchant_details).to.not.equal(merchant_details);
});
}
);
@ -67,16 +165,113 @@ Cypress.Commands.add("apiKeyCreateTest", (apiKeyCreateBody, globalState) => {
method: "POST",
url: `${globalState.get("baseUrl")}/api_keys/${globalState.get("merchantId")}`,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
body: apiKeyCreateBody,
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
// Handle the response as needed
globalState.set("apiKey", response.body.api_key);
globalState.set("apiKeyId", response.body.key_id);
});
});
Cypress.Commands.add("apiKeyUpdateCall", (apiKeyUpdateBody, globalState) => {
const merchant_id = globalState.get("merchantId");
const api_key_id = globalState.get("apiKeyId");
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/api_keys/${merchant_id}/${api_key_id}`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
body: apiKeyUpdateBody,
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
// Handle the response as needed
expect(response.body.name).to.equal("Updated API Key");
expect(response.body.key_id).to.equal(api_key_id);
expect(response.body.merchant_id).to.equal(merchant_id);
});
});
Cypress.Commands.add("apiKeyRetrieveCall", (globalState) => {
const merchant_id = globalState.get("merchantId");
const api_key_id = globalState.get("apiKeyId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/api_keys/${merchant_id}/${api_key_id}`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body.name).to.equal("Updated API Key");
expect(response.body.key_id).to.equal(api_key_id);
expect(response.body.merchant_id).to.equal(merchant_id);
});
});
Cypress.Commands.add("apiKeyListCall", (globalState) => {
const merchant_id = globalState.get("merchantId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/api_keys/${merchant_id}/list`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body).to.be.an("array").and.not.empty;
for (const key in response.body) {
expect(response.body[key]).to.have.property("name").and.not.empty;
expect(response.body[key]).to.have.property("key_id").include("snd_").and
.not.empty;
expect(response.body[key].merchant_id).to.equal(merchant_id);
}
});
});
Cypress.Commands.add("apiKeyDeleteCall", (globalState) => {
const merchant_id = globalState.get("merchantId");
const api_key_id = globalState.get("apiKeyId");
cy.request({
method: "DELETE",
url: `${globalState.get("baseUrl")}/api_keys/${merchant_id}/${api_key_id}`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body.merchant_id).to.equal(merchant_id);
expect(response.body.key_id).to.equal(api_key_id);
expect(response.body.revoked).to.equal(true);
});
});
@ -118,6 +313,10 @@ Cypress.Commands.add(
if (response.status === 200) {
expect(connectorName).to.equal(response.body.connector_name);
globalState.set(
"merchantConnectorId",
response.body.merchant_connector_id
);
} else {
cy.task(
"cli_log",
@ -181,6 +380,10 @@ Cypress.Commands.add(
expect(globalState.get("connectorId")).to.equal(
response.body.connector_name
);
globalState.set(
"merchantConnectorId",
response.body.merchant_connector_id
);
} else {
cy.task(
"cli_log",
@ -236,8 +439,8 @@ Cypress.Commands.add(
method: "POST",
url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
body: createConnectorBody,
@ -249,6 +452,10 @@ Cypress.Commands.add(
expect(globalState.get("connectorId")).to.equal(
response.body.connector_name
);
globalState.set(
"merchantConnectorId",
response.body.merchant_connector_id
);
} else {
cy.task(
"cli_log",
@ -265,6 +472,97 @@ Cypress.Commands.add(
}
);
Cypress.Commands.add("connectorRetrieveCall", (globalState) => {
const merchant_id = globalState.get("merchantId");
const connector_id = globalState.get("connectorId");
const merchant_connector_id = globalState.get("merchantConnectorId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors/${merchant_connector_id}`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body.connector_name).to.equal(connector_id);
expect(response.body.merchant_connector_id).to.equal(merchant_connector_id);
});
});
Cypress.Commands.add("connectorDeleteCall", (globalState) => {
const merchant_id = globalState.get("merchantId");
const merchant_connector_id = globalState.get("merchantConnectorId");
cy.request({
method: "DELETE",
url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors/${merchant_connector_id}`,
headers: {
Accept: "application/json",
"api-key": globalState.get("adminApiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.body.merchant_id).to.equal(merchant_id);
expect(response.body.merchant_connector_id).to.equal(merchant_connector_id);
expect(response.body.deleted).to.equal(true);
});
});
Cypress.Commands.add(
"connectorUpdateCall",
(connectorType, updateConnectorBody, globalState) => {
const merchant_id = globalState.get("merchantId");
const connector_id = globalState.get("connectorId");
const merchant_connector_id = globalState.get("merchantConnectorId");
updateConnectorBody.connector_type = connectorType;
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors/${merchant_connector_id}`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
body: updateConnectorBody,
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body.connector_name).to.equal(connector_id);
expect(response.body.merchant_connector_id).to.equal(
merchant_connector_id
);
expect(response.body.connector_label).to.equal("updated_connector_label");
});
}
);
// Generic function to list all connectors
Cypress.Commands.add("connectorListByMid", (globalState) => {
const merchant_id = globalState.get("merchantId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/account/${merchant_id}/connectors`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("adminApiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body).to.be.an("array").and.not.empty;
});
});
Cypress.Commands.add(
"createCustomerCallTest",
(customerCreateBody, globalState) => {
@ -278,12 +576,109 @@ Cypress.Commands.add(
body: customerCreateBody,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.body.customer_id).to.not.be.empty;
globalState.set("customerId", response.body.customer_id);
});
}
);
Cypress.Commands.add("customerListCall", (globalState) => {
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/customers/list`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
for (const key in response.body) {
expect(response.body[key]).to.not.be.empty;
}
});
});
Cypress.Commands.add("customerRetrieveCall", (globalState) => {
const customer_id = globalState.get("customerId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/customers/${customer_id}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.body.customer_id).to.equal(customer_id).and.not.be.empty;
});
});
Cypress.Commands.add(
"customerUpdateCall",
(customerUpdateBody, globalState) => {
const customer_id = globalState.get("customerId");
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/customers/${customer_id}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
body: customerUpdateBody,
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.body.customer_id).to.equal(customer_id);
});
}
);
Cypress.Commands.add("ephemeralGenerateCall", (globalState) => {
const customer_id = globalState.get("customerId");
const merchant_id = globalState.get("merchantId");
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/ephemeral_keys`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
body: { customer_id: customer_id },
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.body.customer_id).to.equal(customer_id);
expect(response.body.merchant_id).to.equal(merchant_id);
expect(response.body.id).to.exist.and.not.be.empty;
expect(response.body.secret).to.exist.and.not.be.empty;
});
});
Cypress.Commands.add("customerDeleteCall", (globalState) => {
const customer_id = globalState.get("customerId");
cy.request({
method: "DELETE",
url: `${globalState.get("baseUrl")}/customers/${customer_id}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
expect(response.body.customer_id).to.equal(customer_id).and.not.be.empty;
expect(response.body.customer_deleted).to.equal(true);
expect(response.body.address_deleted).to.equal(true);
expect(response.body.payment_methods_deleted).to.equal(true);
});
});
Cypress.Commands.add(
"paymentMethodListTestLessThanEqualToOnePaymentMethod",
(res_data, globalState) => {
@ -1656,6 +2051,7 @@ Cypress.Commands.add("createJWTToken", (req_data, res_data, globalState) => {
});
});
// Specific to routing tests
Cypress.Commands.add("ListMCAbyMID", (globalState) => {
const merchantId = globalState.get("merchantId");
cy.request({