73 lines
3.9 KiB
TypeScript
73 lines
3.9 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("~/components/ui/layouts/EditPageLayout", () => ({ default: ({ children }: { children: React.ReactNode }) => children }));
|
|
vi.mock("~/components/core/users/UsersTable", () => ({ default: () => null }));
|
|
vi.mock("~/components/ui/input/InputFilters", () => ({ default: () => null }));
|
|
vi.mock("~/components/ui/buttons/ButtonPrimary", () => ({ default: () => null }));
|
|
vi.mock("~/components/ui/slideOvers/SlideOverWideEmpty", () => ({ default: ({ children }: { children: React.ReactNode }) => children }));
|
|
vi.mock("~/components/ui/button", () => ({ Button: ({ children }: { children: React.ReactNode }) => children }));
|
|
vi.mock("~/utils/data/useAdminData", () => ({ useAdminData: vi.fn() }));
|
|
vi.mock("~/utils/helpers/PermissionsHelper", () => ({ getUserHasPermission: vi.fn() }));
|
|
vi.mock("~/utils/helpers/.server/PermissionsService", () => ({ verifyUserHasPermission: vi.fn() }));
|
|
vi.mock("~/locale/i18next.server", () => ({ getTranslations: vi.fn() }));
|
|
vi.mock("~/modules/metrics/services/.server/MetricTracker", () => ({ createMetrics: vi.fn() }));
|
|
vi.mock("~/modules/metrics/utils/defaultHeaders", () => ({ serverTimingHeaders: vi.fn() }));
|
|
vi.mock("~/utils/db/users.db.server", () => ({ adminGetAllUsers: vi.fn(), getUser: vi.fn(), updateUserPassword: vi.fn() }));
|
|
vi.mock("~/utils/session.server", () => ({ createUserSession: vi.fn(), getUserInfo: vi.fn(), setLoggedUser: vi.fn() }));
|
|
vi.mock("~/utils/db/tenants.db.server", () => ({ adminGetAllTenantsIdsAndNames: vi.fn(), getTenant: vi.fn() }));
|
|
vi.mock("~/utils/helpers/RowPaginationHelper", () => ({ getFiltersFromCurrentUrl: vi.fn(), getPaginationFromCurrentUrl: vi.fn() }));
|
|
vi.mock("~/modules/events/services/.server/EventsService", () => ({ default: { create: vi.fn() } }));
|
|
vi.mock("~/utils/db/logs.db.server", () => ({ getLastUserLog: vi.fn() }));
|
|
vi.mock("react-hot-toast", () => ({ default: { success: vi.fn(), error: vi.fn() } }));
|
|
vi.mock("bcryptjs", () => ({ default: { hash: vi.fn() } }));
|
|
|
|
import { adminRolesAndPermissionsRedirectTarget, isAdminRolesAndPermissionsRootPath } from "./admin/accounts/roles-and-permissions";
|
|
import { adminImpersonationRedirectTarget } from "./admin/accounts/users";
|
|
|
|
function expectNoLegacyPrefixes(target: string) {
|
|
expect(target).not.toContain("/admin/");
|
|
expect(target).not.toContain("/app/");
|
|
}
|
|
|
|
const routing = {
|
|
appBaseDomain: "example.test",
|
|
webAppHost: "app.example.test",
|
|
adminAppHost: "admin.example.test",
|
|
apiHost: "api.example.test",
|
|
protocol: "https" as const,
|
|
};
|
|
|
|
describe("nested admin host-aware redirects", () => {
|
|
it("redirects the roles-and-permissions root to canonical roles without legacy admin prefixes", () => {
|
|
expect(isAdminRolesAndPermissionsRootPath("/accounts/roles-and-permissions")).toBe(true);
|
|
expect(isAdminRolesAndPermissionsRootPath("/admin/accounts/roles-and-permissions")).toBe(false);
|
|
|
|
const target = adminRolesAndPermissionsRedirectTarget();
|
|
|
|
expect(target).toBe("/accounts/roles-and-permissions/roles");
|
|
expectNoLegacyPrefixes(target);
|
|
});
|
|
|
|
it("builds impersonation tenant dashboard targets without legacy app prefixes", () => {
|
|
const target = adminImpersonationRedirectTarget({ id: "tenant_1", slug: "acme" } as never, routing);
|
|
|
|
expect(target).toBe("https://app.example.test/acme/dashboard");
|
|
expect(target).not.toBe("/app/acme/dashboard");
|
|
expectNoLegacyPrefixes(target);
|
|
});
|
|
|
|
it("keeps the tenant-picker fallback on the canonical app host root", () => {
|
|
const target = adminImpersonationRedirectTarget(null, routing);
|
|
|
|
expect(target).toBe("https://app.example.test/");
|
|
expectNoLegacyPrefixes(target);
|
|
});
|
|
|
|
it("does not fall back to tenant IDs for impersonation redirects", () => {
|
|
const target = adminImpersonationRedirectTarget({ id: "tenant_1", slug: null } as never, routing);
|
|
|
|
expect(target).toBe("https://app.example.test/");
|
|
expect(target).not.toContain("tenant_1");
|
|
});
|
|
});
|