84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
isAuthenticatedUser,
|
|
resolveAuthenticatedNavigation,
|
|
resolveRouteGuardRedirect,
|
|
} from "../navigation-resolver";
|
|
import { ROUTE_BUILDERS, ROUTES } from "../routes";
|
|
|
|
describe("navigation resolver", () => {
|
|
it("treats only real login providers as authenticated users", () => {
|
|
expect(isAuthenticatedUser("notLoggedIn")).toBe(false);
|
|
expect(isAuthenticatedUser("guest")).toBe(false);
|
|
expect(isAuthenticatedUser("email")).toBe(true);
|
|
expect(isAuthenticatedUser("facebook")).toBe(true);
|
|
});
|
|
|
|
it("wraps protected navigation with auth redirect for guests", () => {
|
|
expect(
|
|
resolveAuthenticatedNavigation({
|
|
loginStatus: "guest",
|
|
targetUrl: "/subscription?type=vip",
|
|
}),
|
|
).toBe(ROUTE_BUILDERS.authWithRedirect("/subscription?type=vip"));
|
|
});
|
|
|
|
it("keeps protected navigation targets for authenticated users", () => {
|
|
expect(
|
|
resolveAuthenticatedNavigation({
|
|
loginStatus: "google",
|
|
targetUrl: "/subscription?type=topup",
|
|
}),
|
|
).toBe("/subscription?type=topup");
|
|
});
|
|
|
|
it("allows not logged in users to enter chat for guest bootstrap", () => {
|
|
expect(
|
|
resolveRouteGuardRedirect({
|
|
loginStatus: "notLoggedIn",
|
|
pathname: ROUTES.chat,
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("redirects not logged in session routes except chat to splash", () => {
|
|
expect(
|
|
resolveRouteGuardRedirect({
|
|
loginStatus: "notLoggedIn",
|
|
pathname: ROUTES.sidebar,
|
|
}),
|
|
).toBe(ROUTES.splash);
|
|
});
|
|
|
|
it("redirects non-real users on subscription routes to auth", () => {
|
|
expect(
|
|
resolveRouteGuardRedirect({
|
|
loginStatus: "guest",
|
|
pathname: ROUTES.subscription,
|
|
searchParams: "type=vip&returnTo=chat",
|
|
}),
|
|
).toBe(
|
|
ROUTE_BUILDERS.authWithRedirect(
|
|
"/subscription?type=vip&returnTo=chat",
|
|
),
|
|
);
|
|
});
|
|
|
|
it("allows public and authorized routes", () => {
|
|
expect(
|
|
resolveRouteGuardRedirect({
|
|
loginStatus: "guest",
|
|
pathname: ROUTES.coinsRules,
|
|
}),
|
|
).toBeNull();
|
|
expect(
|
|
resolveRouteGuardRedirect({
|
|
loginStatus: "email",
|
|
pathname: ROUTES.subscription,
|
|
searchParams: "type=vip",
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|