Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composerPullRequestMatches.test.ts

81 lines2.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import type { ThreadPullRequestLink } from "@t3tools/contracts";
4​
5import {
6 composerPullRequestsFromLinks,
7 filterComposerPullRequestMatches,
8} from "./composerPullRequestMatches.ts";
9​
10const entry = (number: number, updatedAt: string) => ({
11 number,
12 projectId: "p1",
13 repository: "owner/repo",
14 updatedAt,
15});
16​
17describe("filterComposerPullRequestMatches", () => {
18 it("ranks the exact number above newer substring matches", () => {
19 const result = filterComposerPullRequestMatches({
20 entries: [entry(1234, "2026-01-03"), entry(123, "2026-01-01"), entry(1230, "2026-01-02")],
21 projectId: "p1",
22 repository: "owner/repo",
23 query: "123",
24 limit: 10,
25 });
26 expect(result.map((match) => match.number)).toEqual([123, 1234, 1230]);
27 });
28});
29​
30describe("linked pull requests", () => {
31 const link = (
32 repository: string,
33 number: number,
34 overrides: Partial<ThreadPullRequestLink> = {},
35 ): ThreadPullRequestLink => ({
36 host: "github.com",
37 repository,
38 number,
39 url: `https://github.com/${repository}/pull/${number}`,
40 source: "agent",
41 linkedAt: "2026-01-01T00:00:00.000Z",
42 snapshot: {
43 state: "open",
44 title: `${repository} ${number}`,
45 headBranch: "feature",
46 baseBranch: "main",
47 isDraft: false,
48 updatedAt: "2026-01-02T00:00:00.000Z",
49 syncedAt: "2026-01-02T00:00:00.000Z",
50 },
51 stack: null,
52 ...overrides,
53 });
54​
55 it("offers a linked pull request from another repository above the project's own", () => {
56 const result = filterComposerPullRequestMatches({
57 entries: [entry(4, "2026-01-03"), { ...entry(4, "2026-01-04"), repository: "owner/other" }],
58 linked: composerPullRequestsFromLinks([link("owner/repo-b", 4)], "p1"),
59 projectId: "p1",
60 repository: "owner/repo",
61 query: "4",
62 limit: 10,
63 });
64 expect(result.map((match) => `${match.repository}#${match.number}`)).toEqual([
65 "owner/repo-b#4",
66 "owner/repo#4",
67 ]);
68 });
69​
70 it("keeps one row for a linked pull request the project listing already has", () => {
71 const result = filterComposerPullRequestMatches({
72 entries: [entry(4, "2026-01-03")],
73 linked: composerPullRequestsFromLinks([link("Owner/Repo", 4)], "p1"),
74 projectId: "p1",
75 repository: "owner/repo",
76 query: "",
77 limit: 10,
78 });
79 expect(result).toEqual([entry(4, "2026-01-03")]);
80 });
81});