Skip to content

Commit 7ca71ee

Browse files
authoredSep 18, 2024
test(verification): add coverage for fetchVerificationKeys() on error (#105)
<!-- This pull request template provides suggested sections for framing your work. You're welcome to change or remove headers if it doesn't fit your use case. :) --> ### What are you trying to accomplish? Improve test coverage for `verification.js` ### Context Relates to #87
1 parent 36c0843 commit 7ca71ee

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 

‎test/verification.test.js

+35
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,41 @@ test("fetchVerificationKeys() - returns cached keys on 304 response", async (t)
263263
t.deepEqual(result, cache);
264264
});
265265

266+
test("fetchVerificationKeys() - throws on non-ok response", async (t) => {
267+
const mockAgent = new MockAgent();
268+
function fetchMock(url, opts) {
269+
opts ||= {};
270+
opts.dispatcher = mockAgent;
271+
return fetch(url, opts);
272+
}
273+
274+
mockAgent.disableNetConnect();
275+
const mockPool = mockAgent.get("https://api.github.com");
276+
mockPool
277+
.intercept({
278+
method: "get",
279+
path: `/meta/public_keys/copilot_api`,
280+
})
281+
.replyWithError(
282+
new Error("Request failed with status code 500"),
283+
);
284+
const testRequest = defaultRequest.defaults({
285+
request: { fetch: fetchMock },
286+
});
287+
288+
const cache = {
289+
id: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"',
290+
keys: publicKeys,
291+
};
292+
293+
await t.throwsAsync(fetchVerificationKeys({
294+
request: testRequest,
295+
cache,
296+
}),{
297+
message: "Request failed with status code 500",
298+
});
299+
});
300+
266301
test("fetchVerificationKeys() - populates and utilizes cache correctly", async (t) => {
267302
const mockAgent = new MockAgent();
268303
function fetchMock(url, opts) {

0 commit comments

Comments
 (0)
Failed to load comments.