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", () => ({ getTrustedClientIpOrNull: 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() } })); 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/billing?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/billing", { tenant: "acme" })).toBe(true); expect(isAppTenantSettingsPath("/app/acme/settings/billing", { tenant: "acme" })).toBe(false); }); });