返回 CodeWhale
public-billing-legal-routes.test.ts
根目录 / web / lib / public-billing-legal-routes.test.ts
1 import { existsSync } from "node:fs";
2 import { describe, expect, it, vi } from "vitest";
3 import { redirect } from "next/navigation";
4 import PricingPage from "../app/[locale]/pricing/page";
5 import { footerLegalLinks } from "./i18n/links";
6 import { getChrome } from "./i18n/dictionaries";
7 import { LEGAL_UPDATED, PRIVACY_SECTIONS, TERMS_SECTIONS } from "./legal-copy";
8
9 const webRoot = new URL("../", import.meta.url);
10 vi.mock("next/navigation", () => ({ redirect: vi.fn() }));
11
12 describe("public legal routes and retired pricing", () => {
13 it("ships real pages for the URLs that used to 404", () => {
14 for (const path of [
15 "app/[locale]/legal/terms/page.tsx",
16 "app/[locale]/legal/privacy/page.tsx",
17 "app/[locale]/privacy/page.tsx",
18 "app/[locale]/terms/page.tsx",
19 ]) {
20 expect(existsSync(new URL(path, webRoot)), path).toBe(true);
21 }
22 });
23
24 it("aliases /privacy and /terms onto the legal paths instead of inventing a second policy", () => {
25 expect(footerLegalLinks("en", getChrome("en")).map((l) => l.href)).toEqual([
26 "/en/legal/terms",
27 "/en/legal/privacy",
28 ]);
29 expect(LEGAL_UPDATED).toBe("September 4, 2026");
30 expect(TERMS_SECTIONS.some((s) => s.title === "Plans and charges")).toBe(true);
31 expect(PRIVACY_SECTIONS.some((s) => s.title === "Retention and deletion")).toBe(true);
32 });
33
34 it("takes incoming pricing links to installation in the visitor's locale", async () => {
35 for (const locale of ["en", "zh", "pt-BR"]) {
36 await PricingPage({ params: Promise.resolve({ locale }) });
37 expect(redirect).toHaveBeenLastCalledWith(`/${locale}/install`);
38 }
39 });
40 });
41
41 lines TYPESCRIPT