Skip to content

Commit

Permalink
test(types): verifyRequestByKeyId(), verifyRequest(), `fetchVerif…
Browse files Browse the repository at this point in the history
…icationKeys()`
  • Loading branch information
gr2m committed Aug 28, 2024
1 parent c94aeb6 commit a38934f
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>(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<boolean>(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<VerificationPublicKey[]>(result);

// accepts a token argument
await fetchVerificationKeys({ token });

// accepts a request argument
await fetchVerificationKeys({ request });
}

0 comments on commit a38934f

Please sign in to comment.