The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { PullRequestCheck, PullRequestDetail } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { resolvePullRequestDetailChecks } from "./pullRequestChecks.ts"; |
| 5 | |
| 6 | const detail = (overrides: Partial<PullRequestDetail> = {}): PullRequestDetail => |
| 7 | ({ title: "Cache the title", state: "open", checks: [], ...overrides }) as PullRequestDetail; |
| 8 | |
| 9 | describe("resolvePullRequestDetailChecks", () => { |
| 10 | it("uses fresh checks for detail counts without replacing other PR fields", () => { |
| 11 | const pending = (name: string): PullRequestCheck => ({ |
| 12 | name, |
| 13 | status: "pending", |
| 14 | url: null, |
| 15 | description: null, |
| 16 | }); |
| 17 | const original = detail({ checks: [pending("build"), pending("test")] }); |
| 18 | const checks = [pending("build"), { ...pending("test"), status: "success" as const }]; |
| 19 | expect(resolvePullRequestDetailChecks(original, { state: "closed", checks }, true)).toEqual({ |
| 20 | ...original, |
| 21 | state: "closed", |
| 22 | checks, |
| 23 | }); |
| 24 | expect(resolvePullRequestDetailChecks(original, { state: "closed", checks }, false)).toBe( |
| 25 | original, |
| 26 | ); |
| 27 | expect(resolvePullRequestDetailChecks(original, null, true)).toBe(original); |
| 28 | expect(resolvePullRequestDetailChecks(null, { state: "closed", checks }, true)).toBeNull(); |
| 29 | }); |
| 30 | |
| 31 | it("keeps newer checks when an older cached detail arrives later", () => { |
| 32 | const pending: PullRequestCheck = { |
| 33 | name: "build", |
| 34 | status: "pending", |
| 35 | url: null, |
| 36 | description: null, |
| 37 | }; |
| 38 | const cached = detail({ observedAt: 1_000, checks: [pending] }); |
| 39 | const checks = { |
| 40 | state: "open" as const, |
| 41 | checks: [{ ...pending, status: "success" as const }], |
| 42 | observedAt: 2_000, |
| 43 | }; |
| 44 | const resolved = resolvePullRequestDetailChecks(cached, checks, false); |
| 45 | expect(resolved?.checks).toEqual(checks.checks); |
| 46 | expect(resolved?.observedAt).toBe(1_000); |
| 47 | expect( |
| 48 | resolvePullRequestDetailChecks(cached, { state: checks.state, checks: checks.checks }, true) |
| 49 | ?.checks, |
| 50 | ).toEqual(checks.checks); |
| 51 | const refreshed = detail({ observedAt: 3_000, checks: [pending] }); |
| 52 | expect(resolvePullRequestDetailChecks(refreshed, checks, true)).toBe(refreshed); |
| 53 | }); |
| 54 | |
| 55 | it("keeps merged details settled while applying newer checks", () => { |
| 56 | const merged = detail({ state: "merged", observedAt: 1_000 }); |
| 57 | const checks = [{ name: "build", status: "success" as const, url: null, description: null }]; |
| 58 | expect( |
| 59 | resolvePullRequestDetailChecks(merged, { state: "open", observedAt: 2_000, checks }, true), |
| 60 | ).toEqual({ ...merged, checks }); |
| 61 | }); |
| 62 | }); |