|
| 1 | +import type { EnvironmentGitHubIssueListEntry } from "@t3tools/client-runtime/state/github-issues"; |
| 2 | +import { describe, expect, it } from "vite-plus/test"; |
| 3 | + |
| 4 | +import { carryGitHubIssueList, gitHubIssueListScope } from "./githubIssueListCarry.logic"; |
| 5 | + |
| 6 | +function entry( |
| 7 | + number: number, |
| 8 | + title: string, |
| 9 | + state: "open" | "closed", |
| 10 | + labels: ReadonlyArray<string> = [], |
| 11 | +): EnvironmentGitHubIssueListEntry { |
| 12 | + return { |
| 13 | + environmentId: "env", |
| 14 | + projectId: "project", |
| 15 | + projectTitle: "Project", |
| 16 | + repository: "acme/app", |
| 17 | + number, |
| 18 | + title, |
| 19 | + url: `https://github.com/acme/app/issues/${number}`, |
| 20 | + author: { login: "octo" }, |
| 21 | + assignees: [], |
| 22 | + labels: labels.map((name) => ({ name, color: "ededed" })), |
| 23 | + state, |
| 24 | + createdAt: "2026-01-01T00:00:00.000Z", |
| 25 | + updatedAt: "2026-01-01T00:00:00.000Z", |
| 26 | + } as unknown as EnvironmentGitHubIssueListEntry; |
| 27 | +} |
| 28 | + |
| 29 | +const held = { |
| 30 | + entries: [ |
| 31 | + entry(1, "Fork fold absorbs repairs", "open", ["dx"]), |
| 32 | + entry(2, "Sync blocked on nightly", "open", ["ci"]), |
| 33 | + entry(3, "Fork tooling sheds flags", "closed"), |
| 34 | + ], |
| 35 | + errors: [], |
| 36 | + environmentErrors: [], |
| 37 | + truncated: true, |
| 38 | +}; |
| 39 | + |
| 40 | +const numbers = (list: ReturnType<typeof carryGitHubIssueList>) => |
| 41 | + list?.entries.map((issue) => issue.number) ?? null; |
| 42 | + |
| 43 | +describe("carryGitHubIssueList", () => { |
| 44 | + it("narrows held rows by every free-text term across title, number and labels", () => { |
| 45 | + expect(numbers(carryGitHubIssueList(held, { state: "all", query: "fork" }))).toEqual([1, 3]); |
| 46 | + expect(numbers(carryGitHubIssueList(held, { state: "all", query: "fork dx" }))).toEqual([1]); |
| 47 | + expect(numbers(carryGitHubIssueList(held, { state: "all", query: "#2" }))).toEqual([2]); |
| 48 | + }); |
| 49 | + |
| 50 | + it("narrows by state, and leaves qualifiers to GitHub", () => { |
| 51 | + expect(numbers(carryGitHubIssueList(held, { state: "closed" }))).toEqual([3]); |
| 52 | + expect(numbers(carryGitHubIssueList(held, { state: "open", query: "label:bug" }))).toEqual([ |
| 53 | + 1, 2, |
| 54 | + ]); |
| 55 | + }); |
| 56 | + |
| 57 | + it("carries nothing rather than an empty list GitHub has not confirmed", () => { |
| 58 | + expect(carryGitHubIssueList(held, { state: "open", query: "nothing matches" })).toBeNull(); |
| 59 | + }); |
| 60 | + |
| 61 | + it("drops the held answer's errors and truncation, which describe another question", () => { |
| 62 | + const carried = carryGitHubIssueList(held, { state: "all" }); |
| 63 | + expect(carried?.truncated).toBe(false); |
| 64 | + expect(carried?.errors).toEqual([]); |
| 65 | + }); |
| 66 | +}); |
| 67 | + |
| 68 | +describe("gitHubIssueListScope", () => { |
| 69 | + it("ignores state and search, but not which projects are asked", () => { |
| 70 | + const open = [{ environmentId: "env", input: { state: "open" as const, projectId: "p" } }]; |
| 71 | + const closed = [ |
| 72 | + { environmentId: "env", input: { state: "closed" as const, projectId: "p", query: "x" } }, |
| 73 | + ]; |
| 74 | + const other = [{ environmentId: "env", input: { state: "open" as const, projectId: "q" } }]; |
| 75 | + expect(gitHubIssueListScope(open as never)).toBe(gitHubIssueListScope(closed as never)); |
| 76 | + expect(gitHubIssueListScope(open as never)).not.toBe(gitHubIssueListScope(other as never)); |
| 77 | + }); |
| 78 | +}); |
0 commit comments