|
5 | 5 | fetchPullRequests, |
6 | 6 | fetchIssuesAndPullRequests, |
7 | 7 | fetchWorkflowRuns, |
| 8 | + fetchPREnrichment, |
8 | 9 | type RepoRef, |
9 | 10 | } from "../../src/app/services/api"; |
10 | 11 | import { clearCache } from "../../src/app/stores/cache"; |
@@ -676,3 +677,105 @@ describe("scaling behavior", () => { |
676 | 677 | }); |
677 | 678 | } |
678 | 679 | }); |
| 680 | + |
| 681 | +// ── fetchPREnrichment: UNSTABLE+pending override ─────────────────────────────── |
| 682 | + |
| 683 | +describe("fetchPREnrichment mergeStateStatus UNSTABLE override", () => { |
| 684 | + function makeEnrichmentOctokit(mergeStateStatus: string, rollupState: string | null) { |
| 685 | + return { |
| 686 | + request: vi.fn(async () => ({ data: [], headers: {} })), |
| 687 | + graphql: vi.fn(async () => ({ |
| 688 | + nodes: [{ |
| 689 | + databaseId: 100, |
| 690 | + headRefOid: "abc123", |
| 691 | + headRepository: { owner: { login: "octocat" }, nameWithOwner: "octocat/Hello-World" }, |
| 692 | + mergeStateStatus, |
| 693 | + assignees: { nodes: [] }, |
| 694 | + reviewRequests: { nodes: [] }, |
| 695 | + latestReviews: { totalCount: 0, nodes: [] }, |
| 696 | + additions: 5, |
| 697 | + deletions: 2, |
| 698 | + changedFiles: 1, |
| 699 | + comments: { totalCount: 0 }, |
| 700 | + reviewThreads: { totalCount: 0 }, |
| 701 | + commits: { |
| 702 | + nodes: rollupState |
| 703 | + ? [{ commit: { statusCheckRollup: { state: rollupState } } }] |
| 704 | + : [], |
| 705 | + }, |
| 706 | + }], |
| 707 | + rateLimit: { limit: 5000, remaining: 4999, resetAt: new Date(Date.now() + 3600000).toISOString() }, |
| 708 | + })), |
| 709 | + paginate: { iterator: vi.fn() }, |
| 710 | + }; |
| 711 | + } |
| 712 | + |
| 713 | + it("preserves pending checkStatus when UNSTABLE and rollup is PENDING", async () => { |
| 714 | + const octokit = makeEnrichmentOctokit("UNSTABLE", "PENDING"); |
| 715 | + const { enrichments } = await fetchPREnrichment(octokit as never, ["PR_node1"]); |
| 716 | + expect(enrichments.get(100)!.checkStatus).toBe("pending"); |
| 717 | + }); |
| 718 | + |
| 719 | + it("forces failure checkStatus when UNSTABLE and rollup is SUCCESS", async () => { |
| 720 | + const octokit = makeEnrichmentOctokit("UNSTABLE", "SUCCESS"); |
| 721 | + const { enrichments } = await fetchPREnrichment(octokit as never, ["PR_node1"]); |
| 722 | + expect(enrichments.get(100)!.checkStatus).toBe("failure"); |
| 723 | + }); |
| 724 | + |
| 725 | + it("forces failure checkStatus when UNSTABLE and rollup is absent", async () => { |
| 726 | + const octokit = makeEnrichmentOctokit("UNSTABLE", null); |
| 727 | + const { enrichments } = await fetchPREnrichment(octokit as never, ["PR_node1"]); |
| 728 | + expect(enrichments.get(100)!.checkStatus).toBe("failure"); |
| 729 | + }); |
| 730 | +}); |
| 731 | + |
| 732 | +// ── fetchPullRequests (graphqlSearchPRs): UNSTABLE+pending override ─────────── |
| 733 | + |
| 734 | +describe("fetchPullRequests processPRNode UNSTABLE override", () => { |
| 735 | + const repos: RepoRef[] = [{ owner: "octocat", name: "Hello-World", fullName: "octocat/Hello-World" }]; |
| 736 | + |
| 737 | + function makePRNodeWithMSS(mergeStateStatus: string, rollupState: string | null) { |
| 738 | + return { |
| 739 | + ...graphqlPRNode, |
| 740 | + mergeStateStatus, |
| 741 | + commits: { |
| 742 | + nodes: rollupState |
| 743 | + ? [{ commit: { statusCheckRollup: { state: rollupState } } }] |
| 744 | + : [], |
| 745 | + }, |
| 746 | + }; |
| 747 | + } |
| 748 | + |
| 749 | + it("preserves pending checkStatus when UNSTABLE and rollup is PENDING", async () => { |
| 750 | + const octokit = makeOctokit(async () => ({ |
| 751 | + search: makeSearchResponse([makePRNodeWithMSS("UNSTABLE", "PENDING")]), |
| 752 | + rateLimit, |
| 753 | + })); |
| 754 | + |
| 755 | + const result = await fetchPullRequests(octokit as unknown as OctokitLike, repos, "testuser"); |
| 756 | + expect(result.pullRequests).toHaveLength(1); |
| 757 | + expect(result.pullRequests[0].checkStatus).toBe("pending"); |
| 758 | + }); |
| 759 | + |
| 760 | + it("forces failure checkStatus when UNSTABLE and rollup is SUCCESS", async () => { |
| 761 | + const octokit = makeOctokit(async () => ({ |
| 762 | + search: makeSearchResponse([makePRNodeWithMSS("UNSTABLE", "SUCCESS")]), |
| 763 | + rateLimit, |
| 764 | + })); |
| 765 | + |
| 766 | + const result = await fetchPullRequests(octokit as unknown as OctokitLike, repos, "testuser"); |
| 767 | + expect(result.pullRequests).toHaveLength(1); |
| 768 | + expect(result.pullRequests[0].checkStatus).toBe("failure"); |
| 769 | + }); |
| 770 | + |
| 771 | + it("forces failure checkStatus when UNSTABLE and rollup is absent", async () => { |
| 772 | + const octokit = makeOctokit(async () => ({ |
| 773 | + search: makeSearchResponse([makePRNodeWithMSS("UNSTABLE", null)]), |
| 774 | + rateLimit, |
| 775 | + })); |
| 776 | + |
| 777 | + const result = await fetchPullRequests(octokit as unknown as OctokitLike, repos, "testuser"); |
| 778 | + expect(result.pullRequests).toHaveLength(1); |
| 779 | + expect(result.pullRequests[0].checkStatus).toBe("failure"); |
| 780 | + }); |
| 781 | +}); |
0 commit comments