chore: only run KV tests if KV is available (#1794)
This commit is contained in:
@@ -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`,
|
||||
]);
|
||||
});
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user