Skip to content

Commit 43c7537

Browse files
committed
test: add failed deployment inspector URL tests
1 parent eed8a08 commit 43c7537

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

apps/web/app/api/sessions/[sessionId]/pr-deployment/route.test.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const currentSessionRecord = {
1313
let currentVercelToken: string | null = "vercel-token";
1414
let currentBranchDeploymentUrl: string | null = null;
1515
let currentBuildingDeploymentUrl: string | null = null;
16+
let currentFailedDeploymentInspectorUrl: string | null = null;
1617
let currentPullRequestDeploymentResult: {
1718
success: boolean;
1819
deploymentUrl?: string | null;
@@ -27,6 +28,9 @@ const findLatestPreviewDeploymentUrlForBranchMock = mock(
2728
const findLatestBuildingDeploymentUrlForBranchMock = mock(
2829
async () => currentBuildingDeploymentUrl,
2930
);
31+
const findLatestFailedDeploymentInspectorUrlForBranchMock = mock(
32+
async () => currentFailedDeploymentInspectorUrl,
33+
);
3034
const getRepoTokenMock = mock(async () => ({ token: "repo-token" }));
3135
const findLatestVercelDeploymentUrlForPullRequestMock = mock(
3236
async () => currentPullRequestDeploymentResult,
@@ -88,10 +92,12 @@ describe("/api/sessions/[sessionId]/pr-deployment", () => {
8892
currentVercelToken = "vercel-token";
8993
currentBranchDeploymentUrl = null;
9094
currentBuildingDeploymentUrl = null;
95+
currentFailedDeploymentInspectorUrl = null;
9196
currentPullRequestDeploymentResult = { success: false };
9297
getUserVercelTokenMock.mockClear();
9398
findLatestPreviewDeploymentUrlForBranchMock.mockClear();
9499
findLatestBuildingDeploymentUrlForBranchMock.mockClear();
100+
findLatestFailedDeploymentInspectorUrlForBranchMock.mockClear();
95101
getRepoTokenMock.mockClear();
96102
findLatestVercelDeploymentUrlForPullRequestMock.mockClear();
97103
});
@@ -223,4 +229,84 @@ describe("/api/sessions/[sessionId]/pr-deployment", () => {
223229
token: "repo-token",
224230
});
225231
});
232+
233+
test("returns failedDeploymentUrl when only a failed deployment exists", async () => {
234+
const { GET } = await routeModulePromise;
235+
236+
currentBranchDeploymentUrl = null;
237+
currentBuildingDeploymentUrl = null;
238+
currentFailedDeploymentInspectorUrl =
239+
"https://vercel.com/team/project/dpl_failed123";
240+
241+
const response = await GET(
242+
new Request("http://localhost/api/sessions/session-1/pr-deployment"),
243+
createRouteContext(),
244+
);
245+
const body = (await response.json()) as {
246+
deploymentUrl: string | null;
247+
buildingDeploymentUrl: string | null;
248+
failedDeploymentUrl: string | null;
249+
};
250+
251+
expect(response.status).toBe(200);
252+
expect(body.deploymentUrl).toBeNull();
253+
expect(body.buildingDeploymentUrl).toBeNull();
254+
expect(body.failedDeploymentUrl).toBe(
255+
"https://vercel.com/team/project/dpl_failed123",
256+
);
257+
});
258+
259+
test("returns failedDeploymentUrl alongside a ready deployment", async () => {
260+
const { GET } = await routeModulePromise;
261+
262+
currentBranchDeploymentUrl = "https://project-preview.vercel.app";
263+
currentBuildingDeploymentUrl = null;
264+
currentFailedDeploymentInspectorUrl =
265+
"https://vercel.com/team/project/dpl_failed456";
266+
267+
const response = await GET(
268+
new Request("http://localhost/api/sessions/session-1/pr-deployment"),
269+
createRouteContext(),
270+
);
271+
const body = (await response.json()) as {
272+
deploymentUrl: string | null;
273+
failedDeploymentUrl: string | null;
274+
};
275+
276+
expect(response.status).toBe(200);
277+
expect(body.deploymentUrl).toBe("https://project-preview.vercel.app");
278+
expect(body.failedDeploymentUrl).toBe(
279+
"https://vercel.com/team/project/dpl_failed456",
280+
);
281+
});
282+
283+
test("does not return failedDeploymentUrl for PR-based lookups", async () => {
284+
const { GET } = await routeModulePromise;
285+
286+
currentSessionRecord.prNumber = 42;
287+
currentFailedDeploymentInspectorUrl =
288+
"https://vercel.com/team/project/dpl_failed789";
289+
currentPullRequestDeploymentResult = {
290+
success: true,
291+
deploymentUrl: "https://pr-preview.vercel.app",
292+
};
293+
294+
const response = await GET(
295+
new Request(
296+
"http://localhost/api/sessions/session-1/pr-deployment?prNumber=42&branch=feature/preview",
297+
),
298+
createRouteContext(),
299+
);
300+
const body = (await response.json()) as {
301+
deploymentUrl: string | null;
302+
failedDeploymentUrl?: string | null;
303+
};
304+
305+
expect(response.status).toBe(200);
306+
expect(body.deploymentUrl).toBe("https://pr-preview.vercel.app");
307+
expect(body.failedDeploymentUrl).toBeUndefined();
308+
expect(
309+
findLatestFailedDeploymentInspectorUrlForBranchMock,
310+
).toHaveBeenCalledTimes(0);
311+
});
226312
});

0 commit comments

Comments
 (0)