91 lines
4.2 KiB
TypeScript
91 lines
4.2 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
|
|
vi.mock("react-router", async () => {
|
|
const actual = await vi.importActual<typeof import("react-router")>("react-router");
|
|
return {
|
|
...actual,
|
|
Link: ({ to, children, ...props }: React.ComponentProps<"a"> & { to: string }) => (
|
|
<a href={to} {...props}>
|
|
{children}
|
|
</a>
|
|
),
|
|
useActionData: () => undefined,
|
|
useLoaderData: () => ({
|
|
currentTenant: { slug: "acme" },
|
|
checkoutSession: { products: [{ title: "Pro" }] },
|
|
error: undefined,
|
|
}),
|
|
useSearchParams: () => [new URLSearchParams()],
|
|
};
|
|
});
|
|
vi.mock("~/components/brand/Logo", () => ({ default: ({ to }: { to?: string }) => <a href={to ?? "/"}>Logo</a> }));
|
|
vi.mock("~/components/core/settings/subscription/plans/PlansGrouped", () => ({ default: () => null }));
|
|
vi.mock("~/components/ui/modals/ErrorModal", () => ({ default: () => null }));
|
|
vi.mock("~/components/public/PublicFooter", () => ({ default: () => null }));
|
|
vi.mock("~/utils/helpers/PermissionsHelper", () => ({ getUserHasPermission: vi.fn(() => true) }));
|
|
vi.mock("~/locale/i18next.server", () => ({ getTranslations: vi.fn() }));
|
|
vi.mock("~/utils/db/tenants.db.server", () => ({ getTenant: vi.fn() }));
|
|
vi.mock("~/utils/db/users.db.server", () => ({ getUser: vi.fn() }));
|
|
vi.mock("~/utils/session.server", () => ({ getUserInfo: vi.fn() }));
|
|
vi.mock("~/utils/services/.server/urlService", () => ({ getTenantIdFromUrl: vi.fn() }));
|
|
vi.mock("~/utils/data/.server/appData", () => ({ loadAppData: vi.fn() }));
|
|
vi.mock("@toolctrl/db/subscriptions.server", () => ({
|
|
createTenantSubscription: vi.fn(),
|
|
getAllSubscriptionProducts: vi.fn(),
|
|
getSubscriptionProductsInIds: vi.fn(),
|
|
getTenantSubscription: vi.fn(),
|
|
updateTenantSubscriptionCustomerId: vi.fn(),
|
|
}));
|
|
vi.mock("~/utils/stripe.server", () => ({ createStripeCheckoutSession: vi.fn(), createStripeCustomer: vi.fn(), getStripeCoupon: vi.fn() }));
|
|
vi.mock("~/utils/url.server", () => ({ getAbsoluteCurrentUrl: vi.fn(), getAbsoluteUrl: vi.fn() }));
|
|
vi.mock("~/utils/helpers/PricingHelper", () => ({ getCurrenciesAndPeriods: vi.fn(), getDefaultBillingPeriod: vi.fn(), getDefaultCurrency: vi.fn() }));
|
|
vi.mock("~/utils/services/.server/pricingService", () => ({ addTenantProductsFromCheckoutSession: vi.fn(), getAcquiredItemsFromCheckoutSession: vi.fn() }));
|
|
vi.mock("~/utils/db/logs.db.server", () => ({ createLog: vi.fn() }));
|
|
vi.mock("~/utils/services/.server/subscriptionService", () => ({ persistCheckoutSessionStatus: vi.fn() }));
|
|
vi.mock("~/modules/metrics/services/.server/MetricTracker", () => ({ createMetrics: vi.fn() }));
|
|
|
|
import {
|
|
subscribeTenantHomePath,
|
|
subscribeTenantSubscriptionSettingsPath,
|
|
} from "./subscribe.$tenant.$session.success";
|
|
import { subscriptionSettingsPath } from "./subscribe.$tenant";
|
|
import { activeTenantDashboardPath } from "./deactivated.$tenant";
|
|
import { planRequiredSubscriptionSettingsPath } from "./plan-required.$tenant";
|
|
|
|
function expectNoLegacyTenantPrefix(target: string) {
|
|
expect(target).not.toContain("/app/acme");
|
|
expect(target).not.toContain("/admin/");
|
|
}
|
|
|
|
describe("subscription and deactivation host-aware navigation", () => {
|
|
it("builds subscription page back links without legacy tenant prefixes", () => {
|
|
const target = subscriptionSettingsPath("acme");
|
|
|
|
expect(target).toBe("/acme/settings/subscription");
|
|
expectNoLegacyTenantPrefix(target);
|
|
});
|
|
|
|
it("builds checkout success navigation without appConfiguration legacy replacement", () => {
|
|
const target = subscribeTenantSubscriptionSettingsPath("acme");
|
|
|
|
expect(target).toBe("/acme/settings/subscription");
|
|
expect(subscribeTenantHomePath("acme")).toBe("/acme");
|
|
expectNoLegacyTenantPrefix(target);
|
|
});
|
|
|
|
it("builds active-tenant deactivation redirects without legacy tenant prefixes", () => {
|
|
const target = activeTenantDashboardPath("acme");
|
|
|
|
expect(target).toBe("/acme/dashboard");
|
|
expectNoLegacyTenantPrefix(target);
|
|
});
|
|
|
|
it("builds plan-required subscription actions without legacy tenant prefixes", () => {
|
|
const target = planRequiredSubscriptionSettingsPath("acme");
|
|
|
|
expect(target).toBe("/acme/settings/subscription");
|
|
expectNoLegacyTenantPrefix(target);
|
|
});
|
|
});
|