test: implement redis unavailibility health check
CI / build (push) Successful in 1m27s

This commit is contained in:
ramvignesh-b
2026-05-11 23:59:01 +05:30
parent 51502055db
commit 2eab4b92cc
3 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ app.onError((err, c) => {
app.get("/health", async (c) => {
if (redis.status !== "ready") {
return c.json({ status: "error", message: "Redis down" }, 503);
return c.json({ status: "error", message: "Redis down", redis: redis.status }, 503);
}
return c.json({ status: "ok" });
});
+11
View File
@@ -35,6 +35,17 @@ describe("API Integration", () => {
expect(body.status).toBe("ok");
});
it("should return 503 for health check if redis is down", async () => {
redis.status = "connecting";
const res = await app.request("/health");
const body = await res.json();
expect(res.status).toBe(503);
expect(body.status).toBe("error");
expect(body.redis).toBe("connecting");
});
it("should return 200 for status with valid API Key", async () => {
redis.keys.mockReturnValue(Promise.resolve(["config:trakt"]));
redis.get.mockImplementation((key) => {
+2
View File
@@ -8,8 +8,10 @@ process.env.PORT = "3000";
// Global Redis mock
mock.module("../src/core/RedisClient", () => ({
redis: {
status: "ready",
get: mock(() => Promise.resolve(null)),
set: mock(() => Promise.resolve()),
keys: mock(() => Promise.resolve([])),
on: mock(() => {}),
},
}));