fix(eoc-push): mappa feedback-tidsstämpel till "skapad" per EOC-kontraktet

This commit is contained in:
Sven (AAMOS AI)
2026-08-11 17:27:53 +07:00
parent af05f084b8
commit 125192f24a
2 changed files with 79 additions and 2 deletions
+38 -1
View File
@@ -1,4 +1,4 @@
import { describe, expect, it, beforeAll, afterAll } from "vitest";
import { describe, expect, it, beforeAll, afterAll, vi } from "vitest";
import IORedis from "ioredis";
import { pushOpsSummaryToEoc } from "../src/processors/eoc-push.js";
@@ -21,6 +21,43 @@ describe("pushOpsSummaryToEoc", () => {
await redis.quit();
});
it("maps feedback.created_at to skapad in the POST body", async () => {
process.env.EOC_URL = "https://eoc.example.com";
process.env.EOC_PUSH_TOKEN = "tok";
const ts = "2026-08-11T10:00:00.000Z";
await redis.set(
"ops:summary:cache",
JSON.stringify({
as_of: ts,
app: { app: "cibello" },
feedback: {
oppna: 1,
senaste: [{ typ: "bug", rubrik: "exempel", status: "oppen", created_at: ts }],
},
}),
"EX",
60,
);
const originalFetch = globalThis.fetch;
const fetchMock = vi.fn().mockResolvedValue(new Response(null, { status: 204 }));
globalThis.fetch = fetchMock as unknown as typeof fetch;
try {
const result = await pushOpsSummaryToEoc(redis);
expect(result.ok).toBe(true);
expect(fetchMock).toHaveBeenCalledTimes(1);
const init = fetchMock.mock.calls[0][1] as RequestInit;
const body = JSON.parse(init.body as string);
expect(body.feedback.senaste[0].skapad).toBe(ts);
expect(body.feedback.senaste[0]).not.toHaveProperty("created_at");
expect(body.as_of).toBe(ts);
} finally {
globalThis.fetch = originalFetch;
}
});
it("returns disabled result when EOC_URL is missing", async () => {
delete process.env.EOC_URL;
process.env.EOC_PUSH_TOKEN = "tok";