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

composerPullRequestMatches.test.ts

48 lines1.5 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { filterComposerPullRequestMatches } from "./composerPullRequestMatches.ts";
4​
5const entry = (number: number, updatedAt: string) => ({
6 number,
7 projectId: "p1",
8 repository: "owner/repo",
9 updatedAt,
10});
11​
12describe("filterComposerPullRequestMatches", () => {
13 it("ranks the exact number above newer substring matches", () => {
14 const result = filterComposerPullRequestMatches({
15 entries: [entry(1234, "2026-01-03"), entry(123, "2026-01-01"), entry(1230, "2026-01-02")],
16 projectId: "p1",
17 repository: "owner/repo",
18 query: "123",
19 limit: 10,
20 });
21 expect(result.map((match) => match.number)).toEqual([123, 1234, 1230]);
22 });
23​
24 it("leaves the caller's array untouched", () => {
25 // The sort runs on a copy; mutating the input would reorder whatever the caller holds.
26 const entries = [entry(2, "2026-01-01"), entry(1, "2026-01-02")];
27 const snapshot = entries.map((match) => match.number);
28 filterComposerPullRequestMatches({
29 entries,
30 projectId: "p1",
31 repository: "owner/repo",
32 query: "",
33 limit: 10,
34 });
35 expect(entries.map((match) => match.number)).toEqual(snapshot);
36 });
37​
38 it("de-duplicates and honours the limit", () => {
39 const result = filterComposerPullRequestMatches({
40 entries: [entry(7, "2026-01-02"), entry(7, "2026-01-01"), entry(8, "2026-01-03")],
41 projectId: "p1",
42 repository: "owner/repo",
43 query: "",
44 limit: 1,
45 });
46 expect(result).toHaveLength(1);
47 });
48});