Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { describePullRequestDiffError } from "./pullRequestDiffError";
4
5describe("describePullRequestDiffError", () => {
6 it("explains the rate limit inside an HTTP transport error without exposing the endpoint", () => {
7 const error =
8 "Failed to fetch remote environment endpoint http://127.0.0.1:49477/api/pull-requests/diff (PullRequestOperationError: Pull request operation diff failed: github requests to github.com are paused until the rate limit resets.).";
9 const result = describePullRequestDiffError(error, "GitHub");
10
11 expect(result.title).toBe("GitHub rate limit reached");
12 expect(result.description).toContain("after the limit resets");
13 expect(result.description).not.toContain("127.0.0.1");
14 expect(result.description).not.toContain("PullRequestOperationError");
15 });
16
17 it("recognizes a provider's API quota error", () => {
18 expect(describePullRequestDiffError("GitHub API rate limit exceeded.", "GitHub").title).toBe(
19 "GitHub rate limit reached",
20 );
21 });
22
23 it("uses the actual host's name for a rate limit", () => {
24 const result = describePullRequestDiffError("Too many requests", "GitLab");
25
26 expect(result.title).toBe("GitLab rate limit reached");
27 expect(result.description).toContain("on GitLab");
28 expect(result.description).not.toContain("GitHub");
29 });
30
31 it("does not blame a rate limit for an unknown connection failure", () => {
32 const result = describePullRequestDiffError(
33 "Failed to fetch remote environment endpoint http://localhost:49477/api/pull-requests/diff (TypeError: Failed to fetch).",
34 "GitHub",
35 );
36
37 expect(result.title).toBe("Couldn't load the changes");
38 expect(result.description).toContain("Try again");
39 expect(result.description).not.toContain("localhost");
40 expect(result.description).not.toContain("limit");
41 });
42});