ops(api): lägg till /ops/v1/health för EOC
This commit is contained in:
@@ -35,6 +35,11 @@ function requireOpsToken(app: FastifyInstance) {
|
|||||||
export async function opsRoutes(app: FastifyInstance) {
|
export async function opsRoutes(app: FastifyInstance) {
|
||||||
const preHandler = [requireOpsToken(app)];
|
const preHandler = [requireOpsToken(app)];
|
||||||
|
|
||||||
|
app.get("/ops/v1/health", { preHandler }, async () => ({
|
||||||
|
ok: true,
|
||||||
|
app: "cibello",
|
||||||
|
}));
|
||||||
|
|
||||||
app.get("/ops/v1/summary", { preHandler }, async (_req, reply) => {
|
app.get("/ops/v1/summary", { preHandler }, async (_req, reply) => {
|
||||||
const [json, ts] = await app.redis.mget(CACHE_KEY, CACHE_TS_KEY);
|
const [json, ts] = await app.redis.mget(CACHE_KEY, CACHE_TS_KEY);
|
||||||
if (!json) {
|
if (!json) {
|
||||||
|
|||||||
@@ -24,6 +24,36 @@ const planPrices = {
|
|||||||
large_household: 19900,
|
large_household: 19900,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe("/ops/v1/health", () => {
|
||||||
|
let app: Awaited<ReturnType<typeof buildServer>>;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
app = await buildServer(config);
|
||||||
|
await app.ready();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await app.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("avvisar anrop utan token", async () => {
|
||||||
|
const res = await app.inject({ method: "GET", url: "/ops/v1/health" });
|
||||||
|
expect(res.statusCode).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returnerar ok med app-namn vid giltig token", async () => {
|
||||||
|
const res = await app.inject({
|
||||||
|
method: "GET",
|
||||||
|
url: "/ops/v1/health",
|
||||||
|
headers: { authorization: `Bearer ${config.OPS_TOKEN}` },
|
||||||
|
});
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
const body = JSON.parse(res.body) as { ok: boolean; app: string };
|
||||||
|
expect(body.ok).toBe(true);
|
||||||
|
expect(body.app).toBe("cibello");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("/ops/v1/summary", () => {
|
describe("/ops/v1/summary", () => {
|
||||||
let app: Awaited<ReturnType<typeof buildServer>>;
|
let app: Awaited<ReturnType<typeof buildServer>>;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user