Skip to content

Commit

Permalink
test(verification): add coverage for fetchVerificationKeys() on err…
Browse files Browse the repository at this point in the history
…or (#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
  • Loading branch information
oscard0m authored Sep 18, 2024
1 parent 36c0843 commit 7ca71ee
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/verification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,41 @@ test("fetchVerificationKeys() - returns cached keys on 304 response", async (t)
t.deepEqual(result, cache);
});

test("fetchVerificationKeys() - throws on non-ok response", async (t) => {
const mockAgent = new MockAgent();
function fetchMock(url, opts) {
opts ||= {};
opts.dispatcher = mockAgent;
return fetch(url, opts);
}

mockAgent.disableNetConnect();
const mockPool = mockAgent.get("https://api.github.com");
mockPool
.intercept({
method: "get",
path: `/meta/public_keys/copilot_api`,
})
.replyWithError(
new Error("Request failed with status code 500"),
);
const testRequest = defaultRequest.defaults({
request: { fetch: fetchMock },
});

const cache = {
id: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"',
keys: publicKeys,
};

await t.throwsAsync(fetchVerificationKeys({
request: testRequest,
cache,
}),{
message: "Request failed with status code 500",
});
});

test("fetchVerificationKeys() - populates and utilizes cache correctly", async (t) => {
const mockAgent = new MockAgent();
function fetchMock(url, opts) {
Expand Down

0 comments on commit 7ca71ee

Please sign in to comment.