Skip to content

Commit d8d8c40

Browse files
sumitdahiya125Sumit Kumarhyperswitch-bot[bot]dracarys18
authored
test(cypress): add test for In Memory Cache (#6961)
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]>
1 parent 228a36d commit d8d8c40

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import State from "../../utils/State";
2+
3+
let globalState;
4+
5+
describe("In Memory Cache Test", () => {
6+
before("seed global state", () => {
7+
cy.task("getGlobalState").then((state) => {
8+
globalState = new State(state);
9+
});
10+
});
11+
12+
after("flush global state", () => {
13+
cy.task("setGlobalState", globalState.data);
14+
});
15+
16+
context("Config flows", () => {
17+
const key = "test-key";
18+
const value = "test value";
19+
const newValue = "new test value";
20+
21+
it("Create Configs", () => {
22+
cy.createConfigs(globalState, key, value);
23+
cy.fetchConfigs(globalState, key, value);
24+
});
25+
26+
it("Update Configs", () => {
27+
cy.updateConfigs(globalState, key, newValue);
28+
cy.fetchConfigs(globalState, key, newValue);
29+
});
30+
31+
it("delete configs", () => {
32+
cy.deleteConfigs(globalState, key, newValue);
33+
});
34+
});
35+
});

cypress-tests/cypress/support/commands.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,3 +3369,95 @@ Cypress.Commands.add("incrementalAuth", (globalState, data) => {
33693369
}
33703370
});
33713371
});
3372+
3373+
Cypress.Commands.add("createConfigs", (globalState, key, value) => {
3374+
const base_url = globalState.get("baseUrl");
3375+
const api_key = globalState.get("adminApiKey");
3376+
3377+
cy.request({
3378+
method: "POST",
3379+
url: `${base_url}/configs/`,
3380+
headers: {
3381+
"Content-Type": "application/json",
3382+
"api-key": api_key,
3383+
},
3384+
body: {
3385+
key: key,
3386+
value: value,
3387+
},
3388+
failOnStatusCode: false,
3389+
}).then((response) => {
3390+
logRequestId(response.headers["x-request-id"]);
3391+
3392+
expect(response.status).to.equal(200);
3393+
expect(response.body).to.have.property("key").to.equal(key);
3394+
expect(response.body).to.have.property("value").to.equal(value);
3395+
});
3396+
});
3397+
3398+
Cypress.Commands.add("fetchConfigs", (globalState, key, value) => {
3399+
const base_url = globalState.get("baseUrl");
3400+
const api_key = globalState.get("adminApiKey");
3401+
3402+
cy.request({
3403+
method: "GET",
3404+
url: `${base_url}/configs/${key}`,
3405+
headers: {
3406+
"Content-Type": "application/json",
3407+
"api-key": api_key,
3408+
},
3409+
failOnStatusCode: false,
3410+
}).then((response) => {
3411+
logRequestId(response.headers["x-request-id"]);
3412+
3413+
expect(response.status).to.equal(200);
3414+
expect(response.body).to.have.property("key").to.equal(key);
3415+
expect(response.body).to.have.property("value").to.equal(value);
3416+
});
3417+
});
3418+
3419+
Cypress.Commands.add("updateConfigs", (globalState, key, value) => {
3420+
const base_url = globalState.get("baseUrl");
3421+
const api_key = globalState.get("adminApiKey");
3422+
3423+
cy.request({
3424+
method: "POST",
3425+
url: `${base_url}/configs/${key}`,
3426+
headers: {
3427+
"Content-Type": "application/json",
3428+
"api-key": api_key,
3429+
},
3430+
body: {
3431+
key: key,
3432+
value: value,
3433+
},
3434+
failOnStatusCode: false,
3435+
}).then((response) => {
3436+
logRequestId(response.headers["x-request-id"]);
3437+
3438+
expect(response.status).to.equal(200);
3439+
expect(response.body).to.have.property("key").to.equal(key);
3440+
expect(response.body).to.have.property("value").to.equal(value);
3441+
});
3442+
});
3443+
3444+
Cypress.Commands.add("deleteConfigs", (globalState, key, value) => {
3445+
const base_url = globalState.get("baseUrl");
3446+
const api_key = globalState.get("adminApiKey");
3447+
3448+
cy.request({
3449+
method: "DELETE",
3450+
url: `${base_url}/configs/${key}`,
3451+
headers: {
3452+
"Content-Type": "application/json",
3453+
"api-key": api_key,
3454+
},
3455+
failOnStatusCode: false,
3456+
}).then((response) => {
3457+
logRequestId(response.headers["x-request-id"]);
3458+
3459+
expect(response.status).to.equal(200);
3460+
expect(response.body).to.have.property("key").to.equal(key);
3461+
expect(response.body).to.have.property("value").to.equal(value);
3462+
});
3463+
});

0 commit comments

Comments
 (0)