|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | + |
| 3 | +vi.mock("@features/auth/hooks/authQueries", () => ({ |
| 4 | + getCachedAuthState: () => ({ cloudRegion: null }), |
| 5 | +})); |
| 6 | + |
| 7 | +import { getBillingUrl, getPostHogUrl } from "./urls"; |
| 8 | + |
| 9 | +describe("getPostHogUrl", () => { |
| 10 | + it("returns null when no region is available and the input is a path", () => { |
| 11 | + expect(getPostHogUrl("/foo")).toBeNull(); |
| 12 | + }); |
| 13 | + |
| 14 | + it.each([ |
| 15 | + ["us", "/foo", "https://us.posthog.com/foo"], |
| 16 | + ["us", "foo", "https://us.posthog.com/foo"], |
| 17 | + ["eu", "/foo", "https://eu.posthog.com/foo"], |
| 18 | + ] as const)( |
| 19 | + "joins base and path for %s region (path=%s)", |
| 20 | + (region, path, expected) => { |
| 21 | + expect(getPostHogUrl(path, region)).toBe(expected); |
| 22 | + }, |
| 23 | + ); |
| 24 | + |
| 25 | + it.each([ |
| 26 | + "https://app.posthog.com/organization/billing", |
| 27 | + "http://localhost:8000/checkout", |
| 28 | + "HTTPS://us.posthog.com/foo", |
| 29 | + ])("passes absolute URLs through unchanged: %s", (url) => { |
| 30 | + expect(getPostHogUrl(url, "us")).toBe(url); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +describe("getBillingUrl", () => { |
| 35 | + it.each([ |
| 36 | + ["us", "https://us.posthog.com/organization/billing/overview"], |
| 37 | + ["eu", "https://eu.posthog.com/organization/billing/overview"], |
| 38 | + ] as const)( |
| 39 | + "points at /organization/billing/overview on %s", |
| 40 | + (region, expected) => { |
| 41 | + expect(getBillingUrl(region)).toBe(expected); |
| 42 | + }, |
| 43 | + ); |
| 44 | + |
| 45 | + it("returns null when no region is available", () => { |
| 46 | + expect(getBillingUrl()).toBeNull(); |
| 47 | + }); |
| 48 | + |
| 49 | + it("does not produce the malformed double-scheme URL we used to ship", () => { |
| 50 | + const url = getBillingUrl("us"); |
| 51 | + expect(url).not.toMatch(/https?:\/\/[^/]+\/https?:/); |
| 52 | + expect(url).not.toContain("/project/"); |
| 53 | + }); |
| 54 | +}); |
0 commit comments