import { describe, it, expect } from "vitest" import { statusToBugzilla, priorityToBugzilla, typeToBugzilla, issueToBugzillaCreate, resolveProductComponent, } from "../../../src/bugzilla/fieldmap.js" import type { Issue } from "../../../src/issue.js" import type { BugzillaTracker } from "../../../src/tracker.js" describe("status mapping", () => { it("maps TODO statuses to Bugzilla", () => { expect(statusToBugzilla("open")).toEqual({ status: "CONFIRMED" }) expect(statusToBugzilla("in-progress")).toEqual({ status: "IN_PROGRESS" }) expect(statusToBugzilla("done")).toEqual({ status: "RESOLVED", resolution: "FIXED" }) expect(statusToBugzilla("hold")).toEqual({ status: "RESOLVED", resolution: "LATER" }) expect(statusToBugzilla("cancelled")).toEqual({ status: "RESOLVED", resolution: "WONTFIX" }) }) }) describe("priority mapping", () => { it("maps TODO priorities to Bugzilla", () => { expect(priorityToBugzilla("low")).toBe("Low") expect(priorityToBugzilla("medium")).toBe("Normal") expect(priorityToBugzilla("high")).toBe("Highest") }) }) describe("type/severity mapping", () => { it("maps TODO types to Bugzilla severity", () => { expect(typeToBugzilla("feature")).toBe("enhancement") expect(typeToBugzilla("bugfix")).toBe("normal") expect(typeToBugzilla("hotfix")).toBe("critical") }) }) describe("issueToBugzillaCreate", () => { it("converts a TODO issue to a Bugzilla create payload", () => { const issue: Issue = { id: 1, type: "feature", title: "Add streaming parser", status: "open", priority: "high", created: "2026-02-05", relationships: { dependsOn: [3] }, description: "Implement streaming JSON parser.", body: "", } const payload = issueToBugzillaCreate(issue, "MyProduct", "MyComponent", "https://example.com/TODO#1") expect(payload.product).toBe("MyProduct") expect(payload.component).toBe("MyComponent") expect(payload.summary).toBe("Add streaming parser") expect(payload.url).toBe("https://example.com/TODO#1") expect(payload.priority).toBe("Highest") expect(payload.severity).toBe("enhancement") expect(payload.depends_on).toEqual([3]) }) }) describe("resolveProductComponent", () => { const tracker: BugzillaTracker = { url: "https://bugzilla.example.com", mappings: [ { module: "General", product: "MyProject", component: "General" }, { module: "Frontend", product: "MyProject", component: "Frontend" }, ], } it("resolves product/component from issue module", () => { const issue = { module: "Frontend" } as Issue const result = resolveProductComponent(issue, tracker) expect(result).toEqual({ product: "MyProject", component: "Frontend" }) }) it("falls back to first mapping when no module set", () => { const issue = {} as Issue const result = resolveProductComponent(issue, tracker) expect(result).toEqual({ product: "MyProject", component: "General" }) }) it("returns null when no tracker", () => { expect(resolveProductComponent({} as Issue, undefined)).toBeNull() }) })