30 行
958 B
TypeScript
30 行
958 B
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { getLoginUrl } from "./const";
|
|
|
|
describe("getLoginUrl", () => {
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
it("falls back to the in-app login route when oauth portal is unset", () => {
|
|
vi.stubEnv("VITE_OAUTH_PORTAL_URL", "");
|
|
|
|
expect(getLoginUrl()).toBe("/login");
|
|
});
|
|
|
|
it("builds the external oauth login url when portal is configured", () => {
|
|
vi.stubEnv("VITE_OAUTH_PORTAL_URL", "https://oauth.example.com");
|
|
vi.stubEnv("VITE_APP_ID", "tennis-training-hub");
|
|
|
|
const url = new URL(getLoginUrl());
|
|
|
|
expect(url.origin).toBe("https://oauth.example.com");
|
|
expect(url.pathname).toBe("/app-auth");
|
|
expect(url.searchParams.get("appId")).toBe("tennis-training-hub");
|
|
expect(url.searchParams.get("redirectUri")).toBe(
|
|
`${window.location.origin}/api/oauth/callback`
|
|
);
|
|
expect(url.searchParams.get("type")).toBe("signIn");
|
|
});
|
|
});
|