This commit is contained in:
+1
-1
@@ -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" });
|
||||
});
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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(() => {}),
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user