import { describe, expect, it } from "bun:test"; import { mirroredEvidenceList, mirrorRedirect, type MirroredEvidenceRow } from "../src/evidence_mirror"; const row = (name: string, contentType: string | null, size: number | null = 10): MirroredEvidenceRow => ({ name, url: `https://cdn.example/${name}`, contentType, size, uploadedAt: 1_792_189_000_000 }); describe("mirroredEvidenceList", () => { it("stands in for the node's list: every mirrored file, with its CDN url", () => { const files = mirroredEvidenceList([ row("flow-r1-en-s3-profile-01-home.png", "image/png", 762204), row("demo-1.mp4", "video/mp4"), ]); expect(files.map((f) => f.name)).toEqual(["demo-1.mp4", "flow-r1-en-s3-profile-01-home.png"]); expect(files[1]).toEqual({ name: "flow-r1-en-s3-profile-01-home.png", size: 762204, mtime: 1_792_189_000_000, isImage: true, isVideo: false, isText: false, url: "https://cdn.example/flow-r1-en-s3-profile-01-home.png", }); expect(files[0]).toMatchObject({ isImage: false, isVideo: true }); }); it("falls back to the extension when content type was not recorded, and 0 for an unknown size", () => { const [f] = mirroredEvidenceList([row("shot.webp", null, null)]); expect(f).toMatchObject({ isImage: true, isVideo: false, size: 0 }); }); }); describe("mirrorRedirect", () => { const urls = new Map([["a.png", "https://cdn.example/a.png"]]); it("redirects a mirrored file to its CDN copy", () => { const res = mirrorRedirect(urls, "a.png"); expect(res?.status).toBe(302); expect(res?.headers.get("location")).toBe("https://cdn.example/a.png"); }); it("returns null for a file that was never mirrored, so the node's own error stands", () => { expect(mirrorRedirect(urls, "session.log")).toBeNull(); }); });