47 lines
2.8 KiB
TypeScript
47 lines
2.8 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("~/components/app/AppLayout", () => ({ default: ({ children }: { children: React.ReactNode }) => children }));
|
|
vi.mock("~/utils/data/useAppData", () => ({ useAppData: vi.fn() }));
|
|
vi.mock("~/utils/data/.server/appData", () => ({ loadAppData: vi.fn() }));
|
|
vi.mock("@hivegrid/db/auth-boundary.server", () => ({
|
|
getAuthUserWithoutPasswordById: vi.fn(),
|
|
getTenantMembershipByIds: vi.fn(),
|
|
updateAuthUserDefaultTenantId: vi.fn(),
|
|
}));
|
|
vi.mock("~/utils/services/.server/urlService", () => ({ getTenantIdFromUrl: vi.fn() }));
|
|
vi.mock("~/utils/session.server", () => ({ getUserInfo: vi.fn() }));
|
|
vi.mock("~/utils/db/appConfiguration.db.server", () => ({ getAppConfiguration: vi.fn() }));
|
|
vi.mock("~/utils/data/useRootData", () => ({ useRootData: vi.fn() }));
|
|
vi.mock("~/components/ui/errors/ServerError", () => ({ default: () => null }));
|
|
vi.mock("~/utils/db/tenants/tenantIpAddress.db.server", () => ({ createUniqueTenantIpAddress: vi.fn() }));
|
|
vi.mock("~/utils/server/IpUtils", () => ({ getClientIPAddress: vi.fn() }));
|
|
vi.mock("~/modules/metrics/services/.server/MetricTracker", () => ({ createMetrics: vi.fn() }));
|
|
vi.mock("~/modules/metrics/utils/defaultHeaders", () => ({ serverTimingHeaders: vi.fn() }));
|
|
vi.mock("~/locale/i18next.server", () => ({ getTranslations: vi.fn() }));
|
|
vi.mock("~/modules/helpDesk/services/Feedback.server", () => ({ default: { send: vi.fn() } }));
|
|
vi.mock("~/stores/themePreviewStore", () => ({ useThemePreviewStore: vi.fn() }));
|
|
vi.mock("~/utils/theme/ThemeConfig", () => ({ getThemeStyle: vi.fn(), parseThemeConfig: vi.fn() }));
|
|
|
|
import { appTenantDeactivatedPath, appTenantPath, appTenantPlanRequiredPath, appTenantSubscriptionRequiredPath, isAppTenantSettingsPath } from "./app.$tenant";
|
|
|
|
describe("app tenant route host-aware guards", () => {
|
|
it("builds subscription-required redirects without legacy app prefixes", () => {
|
|
const target = appTenantPlanRequiredPath({ tenant: "acme" });
|
|
|
|
expect(target).toBe("/plan-required/acme");
|
|
expect(appTenantSubscriptionRequiredPath({ tenant: "acme" })).toBe("/acme/settings/subscription?subscription_required=1");
|
|
expect(target).not.toContain("/app/acme");
|
|
expect(target).not.toContain("/admin/settings");
|
|
});
|
|
|
|
it("builds deactivated redirects through the named tenant helper", () => {
|
|
expect(appTenantDeactivatedPath({ tenant: "acme/west" })).toBe("/deactivated/acme%2Fwest");
|
|
});
|
|
|
|
it("recognizes host-aware tenant settings paths without broad route mocks", () => {
|
|
expect(appTenantPath({ tenant: "acme" }, "settings")).toBe("/acme/settings");
|
|
expect(isAppTenantSettingsPath("/acme/settings/subscription", { tenant: "acme" })).toBe(true);
|
|
expect(isAppTenantSettingsPath("/app/acme/settings/subscription", { tenant: "acme" })).toBe(false);
|
|
});
|
|
});
|