init
This commit is contained in:
commit
932d4ad420
46 changed files with 5800 additions and 0 deletions
87
tests/lib/bugzilla/fieldmap.test.ts
Normal file
87
tests/lib/bugzilla/fieldmap.test.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import { describe, it, expect } from "vitest"
|
||||
import {
|
||||
statusToBugzilla,
|
||||
priorityToBugzilla,
|
||||
typeToBugzilla,
|
||||
issueToBugzillaCreate,
|
||||
resolveProductComponent,
|
||||
} from "../../../lib/bugzilla/fieldmap"
|
||||
import type { Issue } from "../../../lib/issue"
|
||||
import type { BugzillaTracker } from "../../../lib/tracker"
|
||||
|
||||
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()
|
||||
})
|
||||
})
|
||||
44
tests/lib/bugzilla/origin.test.ts
Normal file
44
tests/lib/bugzilla/origin.test.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { describe, it, expect } from "vitest"
|
||||
import {
|
||||
normalizeRemoteUrl,
|
||||
buildOriginUrl,
|
||||
} from "../../../lib/bugzilla/origin"
|
||||
|
||||
describe("normalizeRemoteUrl", () => {
|
||||
it("passes HTTPS URLs through", () => {
|
||||
expect(normalizeRemoteUrl("https://github.com/user/repo"))
|
||||
.toBe("https://github.com/user/repo")
|
||||
})
|
||||
|
||||
it("strips trailing .git", () => {
|
||||
expect(normalizeRemoteUrl("https://github.com/user/repo.git"))
|
||||
.toBe("https://github.com/user/repo")
|
||||
})
|
||||
|
||||
it("converts SSH URLs to HTTPS", () => {
|
||||
expect(normalizeRemoteUrl("git@github.com:user/repo.git"))
|
||||
.toBe("https://github.com/user/repo")
|
||||
})
|
||||
|
||||
it("converts Bitbucket SSH URLs", () => {
|
||||
expect(normalizeRemoteUrl("git@bitbucket.org:org/project.git"))
|
||||
.toBe("https://bitbucket.org/org/project")
|
||||
})
|
||||
})
|
||||
|
||||
describe("buildOriginUrl", () => {
|
||||
it("builds Bitbucket URL with src/<branch>", () => {
|
||||
expect(buildOriginUrl("git@bitbucket.org:byteb4rb1e/mime-todo-spec.git", "master", "TODO", 1))
|
||||
.toBe("https://bitbucket.org/byteb4rb1e/mime-todo-spec/src/master/TODO#1")
|
||||
})
|
||||
|
||||
it("builds GitHub URL with blob/<branch>", () => {
|
||||
expect(buildOriginUrl("https://github.com/user/repo", "main", "TODO", 42))
|
||||
.toBe("https://github.com/user/repo/blob/main/TODO#42")
|
||||
})
|
||||
|
||||
it("builds GitLab URL with -/blob/<branch>", () => {
|
||||
expect(buildOriginUrl("https://gitlab.com/org/repo", "develop", "TODO", 5))
|
||||
.toBe("https://gitlab.com/org/repo/-/blob/develop/TODO#5")
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue