import { describe, expect, it, vi } from "vitest"; vi.mock("~/components/brand/Logo", () => ({ default: () => null })); vi.mock("~/components/screens/auth/CreateWorkspacePage", () => ({ CreateWorkspacePage: () => null })); vi.mock("~/modules/users/components/RegisterForm", () => ({ RegisterForm: () => null })); vi.mock("~/components/ui/buttons/LoadingButton", () => ({ default: () => null })); vi.mock("~/components/ui/modals/ErrorModal", () => ({ default: () => null })); vi.mock("~/components/ui/banners/SuccessBanner", () => ({ default: () => null })); vi.mock("~/components/ui/button", () => ({ Button: ({ children }: { children: React.ReactNode }) => <>{children} })); vi.mock("~/locale/i18next.server", () => ({ getTranslations: vi.fn() })); vi.mock("~/utils/db/logs.db.server", () => ({ createLog: vi.fn() })); vi.mock("~/utils/db/permissions/roles.db.server", () => ({ getAllRoles: vi.fn() })); vi.mock("~/utils/db/tenants.db.server", () => ({ createTenantUser: vi.fn(), getMyTenants: vi.fn(), getTenant: vi.fn() })); vi.mock("~/utils/db/users.db.server", () => ({ getUser: vi.fn(), getUserByEmail: vi.fn(), register: vi.fn() })); vi.mock("~/utils/api/.server/TenantsApi", () => ({ TenantsApi: { create: vi.fn() } })); vi.mock("~/utils/session.server", () => ({ createUserSession: vi.fn(), getUserInfo: vi.fn(), setLoggedUser: vi.fn() })); vi.mock("~/utils/services/.server/pricingService", () => ({ addTenantProductsFromCheckoutSession: vi.fn(), getAcquiredItemsFromCheckoutSession: vi.fn(), })); vi.mock("~/utils/services/.server/subscriptionService", () => ({ persistCheckoutSessionStatus: vi.fn() })); vi.mock("~/utils/services/authService", () => ({ getRegistrationFormData: vi.fn(), validateRegistration: vi.fn() })); vi.mock("~/utils/url.server", () => ({ getAbsoluteUrl: vi.fn() })); vi.mock("~/modules/emails/services/TransactionalEmailQueue.server", () => ({ queueTransactionalEmail: vi.fn() })); vi.mock("~/modules/emails/utils/EmailTemplates", () => ({ default: { WELCOME_EMAIL: { parse: vi.fn() } } })); vi.mock("~/modules/events/services/.server/EventsService", () => ({ default: { create: vi.fn() } })); vi.mock("~/utils/db/appConfiguration.db.server", () => ({ getAppConfiguration: vi.fn() })); import { invitationCreatedUserDashboardPath } from "./invitation.$id"; import { newAccountDashboardPath } from "./new-account"; function expectHostAwareTenantDashboard(target: string) { expect(target).toBe("/example-co/dashboard"); expect(target).not.toContain("/app/example-co"); expect(target).not.toContain("/admin/"); } describe("acquisition completion host-aware redirects", () => { it("builds new-account dashboard targets without legacy app prefixes", () => { expectHostAwareTenantDashboard(newAccountDashboardPath("example-co")); }); it("builds invitation-created-user dashboard targets without legacy app prefixes", () => { expectHostAwareTenantDashboard(invitationCreatedUserDashboardPath({ id: "tenant_1", slug: "example-co" } as never)); }); it("preserves the tenant picker fallback when invitation acceptance has no tenant", () => { const target = invitationCreatedUserDashboardPath(null); expect(target).toBe("/"); expect(target).not.toBe("/app"); }); it("does not fall back to tenant IDs for invitation completion", () => { const target = invitationCreatedUserDashboardPath({ id: "tenant_1", slug: null } as never); expect(target).toBe("/"); expect(target).not.toContain("tenant_1"); }); });