Skip to content

Commit

Permalink
test(cypress): add test for In Memory Cache (juspay#6961)
Browse files Browse the repository at this point in the history
Co-authored-by: Sumit Kumar <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Kartikeya Hegde <[email protected]>
  • Loading branch information
4 people authored Jan 9, 2025
1 parent 228a36d commit d8d8c40
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import State from "../../utils/State";

let globalState;

describe("In Memory Cache Test", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
});
});

after("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});

context("Config flows", () => {
const key = "test-key";
const value = "test value";
const newValue = "new test value";

it("Create Configs", () => {
cy.createConfigs(globalState, key, value);
cy.fetchConfigs(globalState, key, value);
});

it("Update Configs", () => {
cy.updateConfigs(globalState, key, newValue);
cy.fetchConfigs(globalState, key, newValue);
});

it("delete configs", () => {
cy.deleteConfigs(globalState, key, newValue);
});
});
});
92 changes: 92 additions & 0 deletions cypress-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3369,3 +3369,95 @@ Cypress.Commands.add("incrementalAuth", (globalState, data) => {
}
});
});

Cypress.Commands.add("createConfigs", (globalState, key, value) => {
const base_url = globalState.get("baseUrl");
const api_key = globalState.get("adminApiKey");

cy.request({
method: "POST",
url: `${base_url}/configs/`,
headers: {
"Content-Type": "application/json",
"api-key": api_key,
},
body: {
key: key,
value: value,
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);

expect(response.status).to.equal(200);
expect(response.body).to.have.property("key").to.equal(key);
expect(response.body).to.have.property("value").to.equal(value);
});
});

Cypress.Commands.add("fetchConfigs", (globalState, key, value) => {
const base_url = globalState.get("baseUrl");
const api_key = globalState.get("adminApiKey");

cy.request({
method: "GET",
url: `${base_url}/configs/${key}`,
headers: {
"Content-Type": "application/json",
"api-key": api_key,
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);

expect(response.status).to.equal(200);
expect(response.body).to.have.property("key").to.equal(key);
expect(response.body).to.have.property("value").to.equal(value);
});
});

Cypress.Commands.add("updateConfigs", (globalState, key, value) => {
const base_url = globalState.get("baseUrl");
const api_key = globalState.get("adminApiKey");

cy.request({
method: "POST",
url: `${base_url}/configs/${key}`,
headers: {
"Content-Type": "application/json",
"api-key": api_key,
},
body: {
key: key,
value: value,
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);

expect(response.status).to.equal(200);
expect(response.body).to.have.property("key").to.equal(key);
expect(response.body).to.have.property("value").to.equal(value);
});
});

Cypress.Commands.add("deleteConfigs", (globalState, key, value) => {
const base_url = globalState.get("baseUrl");
const api_key = globalState.get("adminApiKey");

cy.request({
method: "DELETE",
url: `${base_url}/configs/${key}`,
headers: {
"Content-Type": "application/json",
"api-key": api_key,
},
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);

expect(response.status).to.equal(200);
expect(response.body).to.have.property("key").to.equal(key);
expect(response.body).to.have.property("value").to.equal(value);
});
});

0 comments on commit d8d8c40

Please sign in to comment.