refactor(router): introduce app navigation manager
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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("redirects not logged in session routes to splash", () => {
|
||||
expect(
|
||||
resolveRouteGuardRedirect({
|
||||
loginStatus: "notLoggedIn",
|
||||
pathname: ROUTES.chat,
|
||||
}),
|
||||
).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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user