Skip to content

Commit 8386d65

Browse files
CopilotByron
andcommitted
Add comprehensive tests for stacked PR error detection
Co-authored-by: Byron <[email protected]>
1 parent d400075 commit 8386d65

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

apps/desktop/src/lib/forge/github/githubPrService.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,75 @@ describe('GitHubPrService', () => {
7070
expect(err.code).toBe(Code.GitHubStackedPrFork);
7171
}
7272
});
73+
74+
test('should not detect stacked PR error for other validation errors', async () => {
75+
const mockError = {
76+
message: 'Validation Failed',
77+
response: {
78+
data: {
79+
message: 'Validation Failed',
80+
errors: [
81+
{
82+
resource: 'PullRequest',
83+
field: 'title',
84+
code: 'missing'
85+
}
86+
]
87+
}
88+
}
89+
};
90+
91+
vi.spyOn(octokit.pulls, 'create').mockRejectedValue(mockError);
92+
93+
try {
94+
await service?.createPr({
95+
title: 'Test PR',
96+
body: 'Test body',
97+
draft: false,
98+
baseBranchName: 'feature-branch',
99+
upstreamName: 'my-branch'
100+
});
101+
expect.fail('Should have thrown an error');
102+
} catch (err: any) {
103+
expect(err.code).not.toBe(Code.GitHubStackedPrFork);
104+
}
105+
});
106+
107+
test('should detect stacked PR error among multiple validation errors', async () => {
108+
const mockError = {
109+
message: 'Validation Failed',
110+
response: {
111+
data: {
112+
message: 'Validation Failed',
113+
errors: [
114+
{
115+
resource: 'Issue',
116+
field: 'title',
117+
code: 'missing'
118+
},
119+
{
120+
resource: 'PullRequest',
121+
field: 'base',
122+
code: 'invalid'
123+
}
124+
]
125+
}
126+
}
127+
};
128+
129+
vi.spyOn(octokit.pulls, 'create').mockRejectedValue(mockError);
130+
131+
try {
132+
await service?.createPr({
133+
title: 'Test PR',
134+
body: 'Test body',
135+
draft: false,
136+
baseBranchName: 'feature-branch',
137+
upstreamName: 'my-branch'
138+
});
139+
expect.fail('Should have thrown an error');
140+
} catch (err: any) {
141+
expect(err.code).toBe(Code.GitHubStackedPrFork);
142+
}
143+
});
73144
});

0 commit comments

Comments
 (0)