From a38934fb1a6628c91e9fb2db4de8334e910af21e Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:00:09 -0700 Subject: [PATCH] test(types): `verifyRequestByKeyId()`, `verifyRequest()`, `fetchVerificationKeys()` --- index.test-d.ts | 52 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/index.test-d.ts b/index.test-d.ts index 69423d3..3596d63 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,32 +1,66 @@ import { expectType } from "tsd"; import { request } from "@octokit/request"; -import { verify } from "./index.js"; +import { + fetchVerificationKeys, + verifyRequest, + verifyRequestByKeyId, + type VerificationPublicKey, +} from "./index.js"; const rawBody = ""; const signature = ""; const keyId = ""; +const key = "" const token = ""; -export async function verifyTest() { - const result = await verify(rawBody, signature, keyId); +export async function verifyRequestByKeyIdTest() { + const result = await verifyRequestByKeyId(rawBody, signature, keyId); expectType(result); // @ts-expect-error - first 3 arguments are required - verify(rawBody, signature); + verifyRequestByKeyId(rawBody, signature); // @ts-expect-error - rawBody must be a string - await verify(1, signature, keyId); + await verifyRequestByKeyId(1, signature, keyId); // @ts-expect-error - signature must be a string - await verify(rawBody, 1, keyId); + await verifyRequestByKeyId(rawBody, 1, keyId); // @ts-expect-error - keyId must be a string - await verify(rawBody, signature, 1); + await verifyRequestByKeyId(rawBody, signature, 1); // accepts a token argument - await verify(rawBody, signature, keyId, { token }); + await verifyRequestByKeyId(rawBody, signature, keyId, { token }); // accepts a request argument - await verify(rawBody, signature, keyId, { request }); + await verifyRequestByKeyId(rawBody, signature, keyId, { request }); } + +export async function verifyRequestTest() { + const result = await verifyRequest(rawBody, signature, key); + expectType(result); + + // @ts-expect-error - first 3 arguments are required + verifyRequest(rawBody, signature); + + // @ts-expect-error - rawBody must be a string + await verifyRequest(1, signature, key); + + // @ts-expect-error - signature must be a string + await verifyRequest(rawBody, 1, key); + + // @ts-expect-error - key must be a string + await verifyRequest(rawBody, signature, 1); +} + +export async function fetchVerificationKeysTest() { + const result = await fetchVerificationKeys(); + expectType(result); + + // accepts a token argument + await fetchVerificationKeys({ token }); + + // accepts a request argument + await fetchVerificationKeys({ request }); +} \ No newline at end of file