Skip to content

Commit 31252c2

Browse files
committed
Change wrapApiConfigurationError to not be serial
1 parent 1991d20 commit 31252c2

1 file changed

Lines changed: 82 additions & 85 deletions

File tree

‎src/api-client.test.ts‎

Lines changed: 82 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -111,103 +111,100 @@ test.serial("getGitHubVersion for GHEC-DR", async (t) => {
111111
t.deepEqual({ type: util.GitHubVariant.GHEC_DR }, gheDotcom);
112112
});
113113

114-
test.serial(
115-
"wrapApiConfigurationError correctly wraps specific configuration errors",
116-
(t) => {
117-
// We don't reclassify arbitrary errors
118-
const arbitraryError = new Error("arbitrary error");
119-
let res = api.wrapApiConfigurationError(arbitraryError);
120-
t.is(res, arbitraryError);
114+
test("wrapApiConfigurationError correctly wraps specific configuration errors", (t) => {
115+
// We don't reclassify arbitrary errors
116+
const arbitraryError = new Error("arbitrary error");
117+
let res = api.wrapApiConfigurationError(arbitraryError);
118+
t.is(res, arbitraryError);
121119

122-
// Same goes for arbitrary errors
123-
const configError = new util.ConfigurationError("arbitrary error");
124-
res = api.wrapApiConfigurationError(configError);
125-
t.is(res, configError);
120+
// Same goes for arbitrary errors
121+
const configError = new util.ConfigurationError("arbitrary error");
122+
res = api.wrapApiConfigurationError(configError);
123+
t.is(res, configError);
126124

127-
// If an HTTP error doesn't contain a specific error message, we don't
128-
// wrap is an an API error.
129-
const httpError = new util.HTTPError("arbitrary HTTP error", 456);
130-
res = api.wrapApiConfigurationError(httpError);
131-
t.is(res, httpError);
125+
// If an HTTP error doesn't contain a specific error message, we don't
126+
// wrap is an an API error.
127+
const httpError = new util.HTTPError("arbitrary HTTP error", 456);
128+
res = api.wrapApiConfigurationError(httpError);
129+
t.is(res, httpError);
132130

133-
// For other HTTP errors, we wrap them as Configuration errors if they contain
134-
// specific error messages.
135-
const httpNotFoundError = new util.HTTPError("commit not found", 404);
136-
res = api.wrapApiConfigurationError(httpNotFoundError);
137-
t.deepEqual(res, new util.ConfigurationError("commit not found"));
131+
// For other HTTP errors, we wrap them as Configuration errors if they contain
132+
// specific error messages.
133+
const httpNotFoundError = new util.HTTPError("commit not found", 404);
134+
res = api.wrapApiConfigurationError(httpNotFoundError);
135+
t.deepEqual(res, new util.ConfigurationError("commit not found"));
138136

139-
const refNotFoundError = new util.HTTPError(
137+
const refNotFoundError = new util.HTTPError(
138+
"ref 'refs/heads/jitsi' not found in this repository - https://docs.github.com/rest",
139+
404,
140+
);
141+
res = api.wrapApiConfigurationError(refNotFoundError);
142+
t.deepEqual(
143+
res,
144+
new util.ConfigurationError(
140145
"ref 'refs/heads/jitsi' not found in this repository - https://docs.github.com/rest",
141-
404,
142-
);
143-
res = api.wrapApiConfigurationError(refNotFoundError);
144-
t.deepEqual(
145-
res,
146-
new util.ConfigurationError(
147-
"ref 'refs/heads/jitsi' not found in this repository - https://docs.github.com/rest",
148-
),
149-
);
146+
),
147+
);
150148

151-
const apiRateLimitError = new util.HTTPError(
152-
"API rate limit exceeded for installation",
153-
403,
154-
);
155-
res = api.wrapApiConfigurationError(apiRateLimitError);
156-
t.deepEqual(
157-
res,
158-
new util.ConfigurationError("API rate limit exceeded for installation"),
159-
);
149+
const apiRateLimitError = new util.HTTPError(
150+
"API rate limit exceeded for installation",
151+
403,
152+
);
153+
res = api.wrapApiConfigurationError(apiRateLimitError);
154+
t.deepEqual(
155+
res,
156+
new util.ConfigurationError("API rate limit exceeded for installation"),
157+
);
160158

161-
const tokenSuggestionMessage =
162-
"Please check that your token is valid and has the required permissions: contents: read, security-events: write";
163-
const badCredentialsError = new util.HTTPError("Bad credentials", 401);
164-
res = api.wrapApiConfigurationError(badCredentialsError);
165-
t.deepEqual(res, new util.ConfigurationError(tokenSuggestionMessage));
159+
const tokenSuggestionMessage =
160+
"Please check that your token is valid and has the required permissions: contents: read, security-events: write";
161+
const badCredentialsError = new util.HTTPError("Bad credentials", 401);
162+
res = api.wrapApiConfigurationError(badCredentialsError);
163+
t.deepEqual(res, new util.ConfigurationError(tokenSuggestionMessage));
166164

167-
const notFoundError = new util.HTTPError("Not Found", 404);
168-
res = api.wrapApiConfigurationError(notFoundError);
169-
t.deepEqual(res, new util.ConfigurationError(tokenSuggestionMessage));
165+
const notFoundError = new util.HTTPError("Not Found", 404);
166+
res = api.wrapApiConfigurationError(notFoundError);
167+
t.deepEqual(res, new util.ConfigurationError(tokenSuggestionMessage));
170168

171-
const resourceNotAccessibleError = new util.HTTPError(
172-
"Resource not accessible by integration",
173-
403,
174-
);
175-
res = api.wrapApiConfigurationError(resourceNotAccessibleError);
176-
t.deepEqual(
177-
res,
178-
new util.ConfigurationError("Resource not accessible by integration"),
179-
);
169+
const resourceNotAccessibleError = new util.HTTPError(
170+
"Resource not accessible by integration",
171+
403,
172+
);
173+
res = api.wrapApiConfigurationError(resourceNotAccessibleError);
174+
t.deepEqual(
175+
res,
176+
new util.ConfigurationError("Resource not accessible by integration"),
177+
);
180178

181-
// Enablement errors.
182-
const enablementErrorMessages = [
183-
"Code Security must be enabled for this repository to use code scanning",
184-
"Advanced Security must be enabled for this repository to use code scanning",
185-
"Code Scanning is not enabled for this repository. Please enable code scanning in the repository settings.",
186-
"Code quality is not enabled for this repository. Please enable code quality in the repository settings.",
187-
];
188-
const transforms = [
189-
(msg: string) => msg,
190-
(msg: string) => msg.toLowerCase(),
191-
(msg: string) => msg.toLocaleUpperCase(),
192-
];
179+
// Enablement errors.
180+
const enablementErrorMessages = [
181+
"Code Security must be enabled for this repository to use code scanning",
182+
"Advanced Security must be enabled for this repository to use code scanning",
183+
"Code Scanning is not enabled for this repository. Please enable code scanning in the repository settings.",
184+
"Code quality is not enabled for this repository. Please enable code quality in the repository settings.",
185+
];
186+
const transforms = [
187+
(msg: string) => msg,
188+
(msg: string) => msg.toLowerCase(),
189+
(msg: string) => msg.toLocaleUpperCase(),
190+
];
193191

194-
for (const enablementErrorMessage of enablementErrorMessages) {
195-
for (const transform of transforms) {
196-
const enablementError = new util.HTTPError(
197-
transform(enablementErrorMessage),
198-
403,
199-
);
200-
res = api.wrapApiConfigurationError(enablementError);
201-
t.deepEqual(
202-
res,
203-
new util.ConfigurationError(
204-
api.getFeatureEnablementError(enablementError.message),
205-
),
206-
);
207-
}
192+
for (const enablementErrorMessage of enablementErrorMessages) {
193+
for (const transform of transforms) {
194+
const enablementError = new util.HTTPError(
195+
transform(enablementErrorMessage),
196+
403,
197+
);
198+
res = api.wrapApiConfigurationError(enablementError);
199+
t.deepEqual(
200+
res,
201+
new util.ConfigurationError(
202+
api.getFeatureEnablementError(enablementError.message),
203+
),
204+
);
208205
}
209-
},
210-
);
206+
}
207+
});
211208

212209
test("getRegistryProxy - returns undefined if the proxy is not configured", async (t) => {
213210
const target = callee(api.getRegistryProxy).withArgs();

0 commit comments

Comments
 (0)