Files
Cibello-app/apps/worker/test/eoc-push.test.ts
T
Sven (AAMOS AI) af05f084b8 feat(worker): EOC push-agent for ops summary
- Add EOC_URL + EOC_PUSH_TOKEN config
- Add pushOpsSummaryToEoc processor
- Schedule PUSH_OPS_SUMMARY_TO_EOC every 2 minutes
- Add unit tests
2026-08-11 17:03:53 +07:00

49 lines
1.6 KiB
TypeScript

import { describe, expect, it, beforeAll, afterAll } from "vitest";
import IORedis from "ioredis";
import { pushOpsSummaryToEoc } from "../src/processors/eoc-push.js";
const redis = new IORedis(process.env.REDIS_URL ?? "redis://localhost:6379", {
maxRetriesPerRequest: null,
});
describe("pushOpsSummaryToEoc", () => {
beforeAll(async () => {
await redis.set(
"ops:summary:cache",
JSON.stringify({ app: { app: "cibello", generated_at: new Date().toISOString() }, as_of: new Date().toISOString() }),
"EX",
60,
);
});
afterAll(async () => {
await redis.del("ops:summary:cache");
await redis.quit();
});
it("returns disabled result when EOC_URL is missing", async () => {
delete process.env.EOC_URL;
process.env.EOC_PUSH_TOKEN = "tok";
const result = await pushOpsSummaryToEoc(redis);
expect(result.ok).toBe(false);
expect(result.error).toMatch(/EOC_URL or EOC_PUSH_TOKEN not configured/);
});
it("returns disabled result when EOC_PUSH_TOKEN is missing", async () => {
process.env.EOC_URL = "https://eoc.example.com";
delete process.env.EOC_PUSH_TOKEN;
const result = await pushOpsSummaryToEoc(redis);
expect(result.ok).toBe(false);
expect(result.error).toMatch(/EOC_URL or EOC_PUSH_TOKEN not configured/);
});
it("returns cache-miss when cache is empty", async () => {
process.env.EOC_URL = "https://eoc.example.com";
process.env.EOC_PUSH_TOKEN = "tok";
await redis.del("ops:summary:cache");
const result = await pushOpsSummaryToEoc(redis);
expect(result.ok).toBe(false);
expect(result.error).toMatch(/cache miss/);
});
});