Skip to content

Commit 2be6da6

Browse files
committed
test: add tests for the wrapApiConfigurationError function
1 parent 76f9ed9 commit 2be6da6

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

lib/api-client.test.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api-client.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api-client.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,47 @@ test("getGitHubVersion for GHE_DOTCOM", async (t) => {
104104
});
105105
t.deepEqual({ type: util.GitHubVariant.GHE_DOTCOM }, gheDotcom);
106106
});
107+
108+
test("wrapApiConfigurationError correctly wraps specific configuration errors", (t) => {
109+
// We don't reclassify arbitrary errors
110+
const arbitraryError = new Error("arbitrary error");
111+
let res = api.wrapApiConfigurationError(arbitraryError);
112+
t.is(res, arbitraryError);
113+
114+
// Same goes for arbitrary errors
115+
const configError = new util.ConfigurationError("arbitrary error");
116+
res = api.wrapApiConfigurationError(configError);
117+
t.is(res, configError);
118+
119+
// If an HTTP error doesn't contain a specific error message, we don't
120+
// wrap is an an API error.
121+
const httpError = new util.HTTPError("arbitrary HTTP error", 456);
122+
res = api.wrapApiConfigurationError(httpError);
123+
t.is(res, httpError);
124+
125+
const httpNotFoundError = new util.HTTPError("commit not found", 404);
126+
res = api.wrapApiConfigurationError(httpNotFoundError);
127+
t.deepEqual(res, new util.ConfigurationError("commit not found"));
128+
129+
const refNotFoundError = new util.HTTPError(
130+
"ref 'refs/heads/jitsi' not found in this repository - https://docs.github.com/rest",
131+
404,
132+
);
133+
res = api.wrapApiConfigurationError(refNotFoundError);
134+
t.deepEqual(
135+
res,
136+
new util.ConfigurationError(
137+
"ref 'refs/heads/jitsi' not found in this repository",
138+
),
139+
);
140+
141+
const apiRateLimitError = new util.HTTPError(
142+
"API rate limit exceeded for installation",
143+
403,
144+
);
145+
res = api.wrapApiConfigurationError(apiRateLimitError);
146+
t.deepEqual(
147+
res,
148+
new util.ConfigurationError("API rate limit exceeded for installation"),
149+
);
150+
});

0 commit comments

Comments
 (0)