Skip to content

Commit d2408cc

Browse files
kristof-siketclaude
andcommitted
test(app): cover multi-page pagination in resolveReadBranch
Address CodeRabbit re-review on #91: the single-page mock never exercised the cursor loop. Add a 2-page case where the requested branch only appears on the second page. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a272740 commit d2408cc

1 file changed

Lines changed: 50 additions & 6 deletions

File tree

packages/cli/tests/read-branch.test.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ type RawBranch = {
1010
role: "production" | "preview";
1111
};
1212

13+
function pageResponse(branches: RawBranch[], nextCursor: string | null) {
14+
return {
15+
data: {
16+
data: branches,
17+
pagination: { hasMore: nextCursor !== null, nextCursor },
18+
},
19+
};
20+
}
21+
1322
function clientReturning(branches: RawBranch[]): ManagementApiClient {
1423
return {
15-
GET: vi.fn().mockResolvedValue({
16-
data: {
17-
data: branches,
18-
pagination: { hasMore: false, nextCursor: null },
19-
},
20-
}),
24+
GET: vi.fn().mockResolvedValue(pageResponse(branches, null)),
2125
} as unknown as ManagementApiClient;
2226
}
2327

@@ -86,4 +90,44 @@ describe("resolveReadBranch", () => {
8690
resolveReadBranch(client, { projectId: "proj_1", branchName: "main" }),
8791
).rejects.toThrow();
8892
});
93+
94+
it("follows pagination to a branch on a later page", async () => {
95+
const GET = vi
96+
.fn()
97+
.mockResolvedValueOnce(
98+
pageResponse(
99+
[
100+
{
101+
id: "b_main",
102+
gitName: "main",
103+
isDefault: true,
104+
role: "production",
105+
},
106+
],
107+
"cursor_1",
108+
),
109+
)
110+
.mockResolvedValueOnce(
111+
pageResponse(
112+
[
113+
{
114+
id: "b_feat",
115+
gitName: "feat/x",
116+
isDefault: false,
117+
role: "preview",
118+
},
119+
],
120+
null,
121+
),
122+
);
123+
const client = { GET } as unknown as ManagementApiClient;
124+
125+
const result = await resolveReadBranch(client, {
126+
projectId: "proj_1",
127+
branchName: "feat/x",
128+
});
129+
130+
expect(result).toEqual({ id: "b_feat", name: "feat/x", kind: "preview" });
131+
expect(GET).toHaveBeenCalledTimes(2);
132+
});
89133
});

0 commit comments

Comments
 (0)