59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import type { WebConfig } from "@toolctrl/config";
|
|
import { getPublicAuthProviders, getServerAuthProviders } from "./authProviders.server";
|
|
|
|
const baseWebConfig: WebConfig = {
|
|
appName: "Test App",
|
|
nodeEnv: "production",
|
|
listen: { host: "0.0.0.0", port: 3000 },
|
|
routing: {
|
|
appBaseDomain: "example.com",
|
|
webAppHost: "app.example.com",
|
|
adminAppHost: "admin.example.com",
|
|
apiHost: "api.example.com",
|
|
protocol: "https",
|
|
},
|
|
stripe: {},
|
|
crisp: {},
|
|
captcha: {},
|
|
analytics: {},
|
|
novu: {},
|
|
mailerSend: {},
|
|
ipProviders: {},
|
|
portalServer: {},
|
|
magicLink: {
|
|
enabled: true,
|
|
tokenTtlMinutes: 15,
|
|
},
|
|
} as unknown as WebConfig;
|
|
|
|
function requestFor(host = "https://app.example.com/dashboard") {
|
|
return new Request(host);
|
|
}
|
|
|
|
describe("authProviders.server", () => {
|
|
test("reports magic-link as enabled and configured when enabled in web config", () => {
|
|
const providers = getServerAuthProviders({ request: requestFor(), webConfig: baseWebConfig });
|
|
|
|
expect(providers.magicLink).toEqual({ enabled: true, configured: true });
|
|
});
|
|
|
|
test("public providers only expose the supported magic-link method", () => {
|
|
const publicProviders = getPublicAuthProviders({ request: requestFor(), webConfig: baseWebConfig });
|
|
|
|
expect(Object.keys(publicProviders)).toEqual(["magicLink"]);
|
|
expect(publicProviders.magicLink).toEqual({ enabled: true, configured: true });
|
|
});
|
|
|
|
test("normalizes disabled magic-link to a safe disabled unconfigured provider", () => {
|
|
const webConfig = {
|
|
...baseWebConfig,
|
|
magicLink: { enabled: false, tokenTtlMinutes: undefined },
|
|
} as WebConfig;
|
|
|
|
const providers = getServerAuthProviders({ request: requestFor(), webConfig });
|
|
|
|
expect(providers.magicLink).toEqual({ enabled: false, configured: false });
|
|
});
|
|
});
|