Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+58
@@ -0,0 +1,58 @@
|
||||
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 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user