mirror of
https://github.com/schpet/linear-cli.git
synced 2026-09-14 14:26:50 +08:00
140 lines
3.6 KiB
TypeScript
140 lines
3.6 KiB
TypeScript
import { assertEquals } from "@std/assert"
|
|
import {
|
|
getIssueIdentifier,
|
|
searchIssuesByTerm,
|
|
} from "../../src/utils/linear.ts"
|
|
import { setupMockLinearServer } from "../utils/test-helpers.ts"
|
|
|
|
Deno.test("getIssueId - handles full issue identifiers", async () => {
|
|
const result = await getIssueIdentifier("ABC-123")
|
|
assertEquals(result, "ABC-123")
|
|
})
|
|
|
|
Deno.test("getIssueId - handles integer-only IDs with team prefix", async () => {
|
|
Deno.env.set("LINEAR_TEAM_ID", "CLI")
|
|
|
|
const result = await getIssueIdentifier("123")
|
|
assertEquals(result, "CLI-123")
|
|
|
|
Deno.env.delete("LINEAR_TEAM_ID")
|
|
})
|
|
|
|
Deno.test("getIssueId - rejects invalid integer patterns", async () => {
|
|
Deno.env.set("LINEAR_TEAM_ID", "TEST")
|
|
|
|
const result = await getIssueIdentifier("0123") // Leading zero should be rejected
|
|
assertEquals(result, undefined)
|
|
|
|
Deno.env.delete("LINEAR_TEAM_ID")
|
|
})
|
|
|
|
Deno.test("getIssueId - rejects zero", async () => {
|
|
Deno.env.set("LINEAR_TEAM_ID", "TEST")
|
|
|
|
const result = await getIssueIdentifier("0")
|
|
assertEquals(result, undefined)
|
|
|
|
Deno.env.delete("LINEAR_TEAM_ID")
|
|
})
|
|
|
|
Deno.test("searchIssuesByTerm - without limit fetches a single page", async () => {
|
|
const { cleanup } = await setupMockLinearServer([
|
|
{
|
|
queryName: "SearchIssues",
|
|
variables: {
|
|
term: "issue",
|
|
filter: {
|
|
team: { key: { eq: "CLI" } },
|
|
},
|
|
},
|
|
response: {
|
|
data: {
|
|
searchIssues: {
|
|
nodes: [
|
|
{
|
|
id: "issue-1",
|
|
identifier: "CLI-1",
|
|
title: "First issue",
|
|
url: "https://linear.app/schpet/issue/CLI-1/first-issue",
|
|
priority: 2,
|
|
priorityLabel: "High",
|
|
estimate: 3,
|
|
createdAt: "2026-04-01T10:00:00.000Z",
|
|
updatedAt: "2026-04-01T10:00:00.000Z",
|
|
state: {
|
|
id: "state-1",
|
|
name: "Backlog",
|
|
color: "#999999",
|
|
type: "backlog",
|
|
},
|
|
assignee: null,
|
|
team: {
|
|
id: "team-1",
|
|
key: "CLI",
|
|
name: "Linear CLI",
|
|
},
|
|
project: null,
|
|
projectMilestone: null,
|
|
cycle: null,
|
|
labels: { nodes: [] },
|
|
metadata: {},
|
|
},
|
|
],
|
|
pageInfo: {
|
|
hasNextPage: true,
|
|
endCursor: "cursor-1",
|
|
},
|
|
totalCount: 2,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
], { NO_COLOR: "true" })
|
|
|
|
try {
|
|
const result = await searchIssuesByTerm("issue", {
|
|
teamKey: "CLI",
|
|
})
|
|
|
|
assertEquals(result, {
|
|
nodes: [
|
|
{
|
|
id: "issue-1",
|
|
identifier: "CLI-1",
|
|
title: "First issue",
|
|
url: "https://linear.app/schpet/issue/CLI-1/first-issue",
|
|
priority: 2,
|
|
priorityLabel: "High",
|
|
estimate: 3,
|
|
createdAt: "2026-04-01T10:00:00.000Z",
|
|
updatedAt: "2026-04-01T10:00:00.000Z",
|
|
state: {
|
|
id: "state-1",
|
|
name: "Backlog",
|
|
color: "#999999",
|
|
type: "backlog",
|
|
},
|
|
assignee: null,
|
|
team: {
|
|
id: "team-1",
|
|
key: "CLI",
|
|
name: "Linear CLI",
|
|
},
|
|
project: null,
|
|
projectMilestone: null,
|
|
cycle: null,
|
|
labels: { nodes: [] },
|
|
metadata: {},
|
|
},
|
|
],
|
|
pageInfo: {
|
|
hasNextPage: true,
|
|
endCursor: "cursor-1",
|
|
},
|
|
totalCount: 2,
|
|
})
|
|
} finally {
|
|
await cleanup()
|
|
}
|
|
})
|