one
Version:
One is a new React Framework that makes Vite serve both native and web.
24 lines (23 loc) • 1.26 kB
JavaScript
import { afterEach, describe, expect, it } from "vitest";
import { isRouteProtected, registerProtectedRoutes, resolveProtectedHref, unregisterProtectedRoutes } from "./router.mjs";
const contextKey = "/account";
afterEach(() => {
unregisterProtectedRoutes(contextKey);
});
describe("protected route redirects", () => {
it("resolves a protected href to its redirect target", () => {
registerProtectedRoutes(contextKey, /* @__PURE__ */new Map([["settings", "/login"]]));
expect(isRouteProtected("/account/settings?tab=billing")).toBe(true);
expect(resolveProtectedHref("/account/settings?tab=billing")).toBe("/login");
});
it("blocks a protected href without an explicit target", () => {
registerProtectedRoutes(contextKey, /* @__PURE__ */new Map([["settings", void 0]]));
expect(resolveProtectedHref("/account/settings")).toBeUndefined();
});
it("leaves allowed and similarly prefixed routes unchanged", () => {
registerProtectedRoutes(contextKey, /* @__PURE__ */new Map([["settings", "/login"]]));
expect(resolveProtectedHref("/account/profile")).toBe("/account/profile");
expect(resolveProtectedHref("/accounting/settings")).toBe("/accounting/settings");
});
});
//# sourceMappingURL=protectedRoutes.test.mjs.map