test(cypress): add test for In Memory Cache (#6961)

Co-authored-by: Sumit Kumar <sumit.kumar@Sumit-Kumar-D9GXRYR75W.local>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Kartikeya Hegde <karthikey.hegde@juspay.in>
This commit is contained in:
sumitdahiya125
2025-01-09 15:02:36 +05:30
committed by GitHub
parent 228a36deeb
commit d8d8c400bb
3 changed files with 127 additions and 0 deletions

View File

@ -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);
});
});
});

View File

@ -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);
});
});