Skip to content

Commit

Permalink
feat: validate more key_id types based on env
Browse files Browse the repository at this point in the history
  • Loading branch information
pixincreate committed Nov 6, 2024
1 parent 0ff5e64 commit 413bfeb
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions cypress-tests-v2/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ Cypress.Commands.add(
// Define the necessary variables and constants
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "publishable_key";
const key_id = validateEnv(base_url, key_id_type);
const organization_id = globalState.get("organizationId");
const url = `${base_url}/v2/merchant_accounts`;

Expand All @@ -202,14 +204,9 @@ Cypress.Commands.add(
.and.to.include(`${merchant_name}_`)
.and.to.be.a("string").and.not.be.empty;

if (base_url.includes("sandbox") || base_url.includes("integ"))
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_snd").and.to.not.be.empty;
else if (base_url.includes("localhost"))
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_dev").and.to.not.be.empty;
expect(response.body)
.to.have.property(key_id_type)
.and.to.include(key_id).and.to.not.be.empty;

globalState.set("merchantId", response.body.id);
globalState.set("publishableKey", response.body.publishable_key);
Expand All @@ -228,6 +225,8 @@ Cypress.Commands.add("merchantAccountRetrieveCall", (globalState) => {
// Define the necessary variables and constants
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "key_id";
const key_id = validateEnv(base_url, key_id_type);
const merchant_id = globalState.get("merchantId");
const url = `${base_url}/v2/merchant_accounts/${merchant_id}`;

Expand All @@ -246,14 +245,8 @@ Cypress.Commands.add("merchantAccountRetrieveCall", (globalState) => {
expect(response.body).to.have.property("id").and.to.be.a("string").and.not
.be.empty;

if (base_url.includes("sandbox") || base_url.includes("integ"))
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_snd").and.to.not.be.empty;
else
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_dev").and.to.not.be.empty;
expect(response.body).to.have.property(key_id_type).and.to.include(key_id)
.and.to.not.be.empty;

if (merchant_id === undefined || merchant_id === null) {
globalState.set("merchantId", response.body.id);
Expand All @@ -274,6 +267,8 @@ Cypress.Commands.add(
// Define the necessary variables and constants
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "key_id";
const key_id = validateEnv(base_url, key_id_type);
const merchant_id = globalState.get("merchantId");
const url = `${base_url}/v2/merchant_accounts/${merchant_id}`;

Expand All @@ -294,14 +289,10 @@ Cypress.Commands.add(
if (response.status === 200) {
expect(response.body.id).to.equal(merchant_id);

if (base_url.includes("sandbox") || base_url.includes("integ"))
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_snd").and.to.not.be.empty;
else
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_dev").and.to.not.be.empty;
expect(response.body)
.to.have.property(key_id_type)
.and.to.include(key_id).and.to.not.be.empty;

expect(response.body.merchant_name).to.equal(merchant_name);

if (merchant_id === undefined || merchant_id === null) {
Expand Down

0 comments on commit 413bfeb

Please sign in to comment.