chore: only run KV tests if KV is available (#1794)

This commit is contained in:
Marvin Hagemeister
2023-09-19 13:04:35 +02:00
committed by GitHub
parent 567df19f3d
commit 4a8bfc0327
+62 -44
View File
@@ -1,53 +1,71 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import kvOAuthPlugin from "$fresh/plugins/kv_oauth.ts";
import {
assert,
assertArrayIncludes,
assertNotEquals,
} from "$std/testing/asserts.ts";
import { oauth2Client } from "./plugin_test_utils.ts";
import { colors } from "$fresh/src/server/deps.ts";
Deno.test("kvOAuthPlugin() works correctly", async (test) => {
await test.step("with default values", () => {
const plugin = kvOAuthPlugin(oauth2Client);
assertNotEquals(plugin.routes, undefined);
assert(plugin.routes!.every((route) => route.handler !== undefined));
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
"/oauth/signin",
"/oauth/callback",
"/oauth/signout",
]);
});
// @ts-ignore openKv is only available with --unstable
const hasKVEnabled = typeof Deno.openKv === "function";
if (!hasKVEnabled) {
console.log(
colors.yellow(`Skipping Deno KV tests. Pass "--unstable" to run them.`),
);
}
await test.step("with defined values", () => {
const signInPath = "/signin";
const callbackPath = "/callback";
const signOutPath = "/signout";
const plugin = kvOAuthPlugin(oauth2Client, {
signInPath,
callbackPath,
signOutPath,
});
assertNotEquals(plugin.routes, undefined);
assert(plugin.routes!.every((route) => route.handler !== undefined));
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
signInPath,
callbackPath,
signOutPath,
]);
});
Deno.test(
{
name: "kvOAuthPlugin() works correctly",
ignore: !hasKVEnabled,
sanitizeResources: false,
fn: async (test) => {
const { oauth2Client } = await import("./plugin_test_utils.ts");
const kvOAuthPlugin =
(await import("$fresh/plugins/kv_oauth.ts")).default;
await test.step("with mapped providers", () => {
const providerKey = "customProvider";
const plugin = kvOAuthPlugin({
[providerKey]: oauth2Client,
});
assertNotEquals(plugin.routes, undefined);
assert(plugin.routes!.every((route) => route.handler !== undefined));
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
`/oauth/${providerKey}/signin`,
`/oauth/${providerKey}/callback`,
`/oauth/${providerKey}/signout`,
]);
});
});
await test.step("with default values", () => {
const plugin = kvOAuthPlugin(oauth2Client);
assertNotEquals(plugin.routes, undefined);
assert(plugin.routes!.every((route) => route.handler !== undefined));
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
"/oauth/signin",
"/oauth/callback",
"/oauth/signout",
]);
});
await test.step("with defined values", () => {
const signInPath = "/signin";
const callbackPath = "/callback";
const signOutPath = "/signout";
const plugin = kvOAuthPlugin(oauth2Client, {
signInPath,
callbackPath,
signOutPath,
});
assertNotEquals(plugin.routes, undefined);
assert(plugin.routes!.every((route) => route.handler !== undefined));
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
signInPath,
callbackPath,
signOutPath,
]);
});
await test.step("with mapped providers", () => {
const providerKey = "customProvider";
const plugin = kvOAuthPlugin({
[providerKey]: oauth2Client,
});
assertNotEquals(plugin.routes, undefined);
assert(plugin.routes!.every((route) => route.handler !== undefined));
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
`/oauth/${providerKey}/signin`,
`/oauth/${providerKey}/callback`,
`/oauth/${providerKey}/signout`,
]);
});
},
},
);