import { describe, expect, it } from "bun:test"; import { DEFAULT_TIMELINE_SOURCES } from "../types/timeline"; import { isLinearConfigured, type LinearIssueEvent, linearEventToTimelineRow, } from "./linear"; describe("isLinearConfigured", () => { it("returns true when a key is passed explicitly", () => { expect(isLinearConfigured("lin_api_xxx")).toBe(true); }); it("returns false for empty/undefined key with no env", () => { const prev = process.env.LINEAR_API_KEY; process.env.LINEAR_API_KEY = ""; expect(isLinearConfigured("")).toBe(false); if (prev === undefined) { process.env.LINEAR_API_KEY = undefined as unknown as string; } else { process.env.LINEAR_API_KEY = prev; } }); }); describe("linearEventToTimelineRow", () => { const event: LinearIssueEvent = { id: "linear-completed-abc123", timestamp: new Date("2026-06-26T12:00:00.000Z"), issueId: "abc123", issueIdentifier: "OPL-2376", title: "Make Linear a first-class source", action: "completed", teamName: "OPL", projectName: "Scribe", assigneeName: "Satchmo", url: "https://linear.app/openprotocollabs/issue/OPL-2376", estimatedMinutes: 5, }; it("emits a source that is a visible default timeline source", () => { // Regression: linear was missing from DEFAULT_TIMELINE_SOURCES, so ingested // Linear events were silently filtered out of the timeline. Keep the adapter // output in sync with the display contract. const row = linearEventToTimelineRow(event); expect(DEFAULT_TIMELINE_SOURCES).toContain(row.source); }); it("maps a Linear event to a timeline_events insert row", () => { const row = linearEventToTimelineRow(event); expect(row.source).toBe("linear"); expect(row.sourceId).toBe("linear-completed-abc123"); // stable dedup key expect(row.projectRootId).toBeNull(); // API source, no local root expect(row.timestamp).toEqual(event.timestamp); expect(row.estimatedMinutes).toBe(5); expect(row.content).toBe("OPL-2376 Make Linear a first-class source"); expect(row.metadata).toEqual({ issueId: "abc123", issueIdentifier: "OPL-2376", title: "Make Linear a first-class source", action: "completed", teamName: "OPL", projectName: "Scribe", assigneeName: "Satchmo", url: "https://linear.app/openprotocollabs/issue/OPL-2376", }); }); });