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.
|
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
|
||||||
import kvOAuthPlugin from "$fresh/plugins/kv_oauth.ts";
|
|
||||||
import {
|
import {
|
||||||
assert,
|
assert,
|
||||||
assertArrayIncludes,
|
assertArrayIncludes,
|
||||||
assertNotEquals,
|
assertNotEquals,
|
||||||
} from "$std/testing/asserts.ts";
|
} 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) => {
|
// @ts-ignore openKv is only available with --unstable
|
||||||
await test.step("with default values", () => {
|
const hasKVEnabled = typeof Deno.openKv === "function";
|
||||||
const plugin = kvOAuthPlugin(oauth2Client);
|
if (!hasKVEnabled) {
|
||||||
assertNotEquals(plugin.routes, undefined);
|
console.log(
|
||||||
assert(plugin.routes!.every((route) => route.handler !== undefined));
|
colors.yellow(`Skipping Deno KV tests. Pass "--unstable" to run them.`),
|
||||||
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
|
);
|
||||||
"/oauth/signin",
|
}
|
||||||
"/oauth/callback",
|
|
||||||
"/oauth/signout",
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
await test.step("with defined values", () => {
|
Deno.test(
|
||||||
const signInPath = "/signin";
|
{
|
||||||
const callbackPath = "/callback";
|
name: "kvOAuthPlugin() works correctly",
|
||||||
const signOutPath = "/signout";
|
ignore: !hasKVEnabled,
|
||||||
const plugin = kvOAuthPlugin(oauth2Client, {
|
sanitizeResources: false,
|
||||||
signInPath,
|
fn: async (test) => {
|
||||||
callbackPath,
|
const { oauth2Client } = await import("./plugin_test_utils.ts");
|
||||||
signOutPath,
|
const kvOAuthPlugin =
|
||||||
});
|
(await import("$fresh/plugins/kv_oauth.ts")).default;
|
||||||
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", () => {
|
await test.step("with default values", () => {
|
||||||
const providerKey = "customProvider";
|
const plugin = kvOAuthPlugin(oauth2Client);
|
||||||
const plugin = kvOAuthPlugin({
|
assertNotEquals(plugin.routes, undefined);
|
||||||
[providerKey]: oauth2Client,
|
assert(plugin.routes!.every((route) => route.handler !== undefined));
|
||||||
});
|
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
|
||||||
assertNotEquals(plugin.routes, undefined);
|
"/oauth/signin",
|
||||||
assert(plugin.routes!.every((route) => route.handler !== undefined));
|
"/oauth/callback",
|
||||||
assertArrayIncludes(plugin.routes!.map((route) => route.path), [
|
"/oauth/signout",
|
||||||
`/oauth/${providerKey}/signin`,
|
]);
|
||||||
`/oauth/${providerKey}/callback`,
|
});
|
||||||
`/oauth/${providerKey}/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