From 659a1084590a49e3dba075f7d3459c32bc58faee Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Tue, 17 Sep 2024 20:10:23 -0700 Subject: [PATCH] test: adapt latest changes from `main` to conditional request APIs --- test/verification.test.js | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/test/verification.test.js b/test/verification.test.js index b9e9156..8563e7e 100644 --- a/test/verification.test.js +++ b/test/verification.test.js @@ -59,7 +59,7 @@ test("verifyRequestByKeyId()", async (t) => { "content-type": "application/json", "x-request-id": "", }, - } + }, ); const testRequest = defaultRequest.defaults({ request: { fetch: fetchMock }, @@ -103,7 +103,7 @@ test("verifyRequestByKeyId() - throws if keyId not present in verification keys "content-type": "application/json", "x-request-id": "", }, - } + }, ); const testRequest = defaultRequest.defaults({ request: { fetch: fetchMock }, @@ -117,7 +117,7 @@ test("verifyRequestByKeyId() - throws if keyId not present in verification keys name: "Error", message: "[@copilot-extensions/preview-sdk] No public key found matching key identifier", - } + }, ); }); @@ -208,7 +208,7 @@ test("fetchVerificationKeys() - without cache", async (t) => { "content-type": "application/json", "x-request-id": "", }, - } + }, ); const testRequest = defaultRequest.defaults({ request: { fetch: fetchMock }, @@ -250,7 +250,10 @@ test("fetchVerificationKeys() - returns cached keys on 304 response", async (t) request: { fetch: fetchMock }, }); - const cache = { id: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"', keys: publicKeys }; + const cache = { + id: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"', + keys: publicKeys, + }; const result = await fetchVerificationKeys({ request: testRequest, @@ -285,7 +288,7 @@ test("fetchVerificationKeys() - populates and utilizes cache correctly", async ( { headers: { "content-type": "application/json", - "etag": 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"', + etag: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"', "x-request-id": "", }, }, @@ -300,7 +303,10 @@ test("fetchVerificationKeys() - populates and utilizes cache correctly", async ( request: testRequest, }); - const expectedCache = { id: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"', keys: publicKeys }; + const expectedCache = { + id: 'W/"db60f89fb432b6c2362ac024c9322df5e6e2a8326595f7c1d35f807767d66e85"', + keys: publicKeys, + }; t.deepEqual(firstResult, expectedCache); // Second request: respond with 304 @@ -370,8 +376,9 @@ test("fetchVerificationKeys() - with token", async (t) => { headers: { "content-type": "application/json", "x-request-id": "", + etag: 'W/"123"', }, - } + }, ); const testRequest = defaultRequest.defaults({ request: { fetch: fetchMock }, @@ -382,5 +389,19 @@ test("fetchVerificationKeys() - with token", async (t) => { request: testRequest, }); - t.deepEqual(result, publicKeys); + t.deepEqual(result, { + id: 'W/"123"', + keys: [ + { + is_current: true, + key: "", + key_identifier: "", + }, + { + is_current: true, + key: "", + key_identifier: "", + }, + ], + }); });