create-ailk 0.46.2 → 0.46.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,7 @@ import { Pricing } from "@working-theory/ui/sections";
12
12
  import {
13
13
  parseLookupKey,
14
14
  PricingSectionDataSchema,
15
+ type OfferingsContactProduct,
15
16
  workspaceShownSetSchema,
16
17
  type OfferingsPrice,
17
18
  type OfferingsProduct,
@@ -24,6 +25,8 @@ import {
24
25
  OFFERINGS_CHECKOUT_PATH,
25
26
  offeringsBundleHref,
26
27
  offeringsCheckoutHref,
28
+ collectionPlans,
29
+ offeringsPlanColumns,
27
30
  offeringsPricing,
28
31
  type OfferingsPricing,
29
32
  type OfferingsPricingLabels,
@@ -38,6 +41,13 @@ const LABELS: OfferingsPricingLabels = {
38
41
  withRequired: (plan, required) => "W⟪" + plan + "⟫" + required,
39
42
  depositNote: (deposit) => "D⟪" + deposit,
40
43
  billedYearly: (amount) => "B⟪" + amount,
44
+ custom: "C⟪",
45
+ // #12242 D2 — sentinels, so a unit the mapper builds shows where each word came from.
46
+ perMonth: "PM⟪",
47
+ perYear: "PY⟪",
48
+ unitWithLabel: (period, label) => "U⟪" + period + "⟫" + label,
49
+ savings: (percent) => "S⟪" + percent,
50
+ regularPrice: (regular, current) => "R⟪" + regular + "⟫" + current,
41
51
  };
42
52
 
43
53
  const OPTIONS = { locale: "en-US", labels: LABELS };
@@ -177,16 +187,10 @@ function plansOf(result: OfferingsPricing) {
177
187
  return result.plans.plans;
178
188
  }
179
189
 
180
- /** The mapper's tiles carry `key` beside the fields `AddonCard` reads (D3). */
181
- type Tile = NonNullable<
182
- NonNullable<OfferingsPricing["addons"]>["addons"]
183
- >[number] & {
184
- key: string;
185
- };
186
-
187
- function addonsOf(result: OfferingsPricing): Tile[] {
188
- if (!result.addons?.addons) throw new Error("expected an add-ons fragment");
189
- return result.addons.addons as Tile[];
190
+ /** The add-ons fragment's cards (#12241 D3): plan cards, each keyed by its `{plan}`. */
191
+ function addonsOf(result: OfferingsPricing) {
192
+ if (!result.addons) throw new Error("expected an add-ons fragment");
193
+ return result.addons.plans;
190
194
  }
191
195
 
192
196
  function card(result: OfferingsPricing, key: string) {
@@ -195,9 +199,9 @@ function card(result: OfferingsPricing, key: string) {
195
199
  return found;
196
200
  }
197
201
 
198
- function tile(result: OfferingsPricing, key: string) {
202
+ function addonCard(result: OfferingsPricing, key: string) {
199
203
  const found = addonsOf(result).find((t) => t.key === key);
200
- if (!found) throw new Error(`no tile ${key}`);
204
+ if (!found) throw new Error(`no add-on card ${key}`);
201
205
  return found;
202
206
  }
203
207
 
@@ -240,7 +244,7 @@ describe("offeringsPricing — one card per Product (AC-1)", () => {
240
244
  "seo-audit",
241
245
  "audit-pack",
242
246
  ]);
243
- expect(result.addons?.plans).toEqual([]);
247
+ expect(result.addons).not.toHaveProperty("addons");
244
248
  expect(result.plans?.variant).toBe("three-tiers-with-toggle");
245
249
  expect(result.plans?.cardLayout).toBe("centered");
246
250
  expect(result.addons?.variant).toBe("addons");
@@ -257,8 +261,9 @@ describe("offeringsPricing — one card per Product (AC-1)", () => {
257
261
  });
258
262
  const flagged = addonsOf(result).filter((t) => t.eyebrow !== undefined);
259
263
  expect(flagged.map((t) => t.key)).toEqual(["seo-audit"]);
260
- expect(flagged[0]).toMatchObject({ eyebrow: "REC⟪", checkTone: "primary" });
261
- expect(tile(result, "audit-pack").checkTone).toBeUndefined();
264
+ expect(flagged[0]).toMatchObject({ eyebrow: "REC⟪" });
265
+ // #12241 D3 — an add-on card is never highlighted, the recommended one included.
266
+ expect(addonsOf(result).filter((t) => t.highlighted)).toEqual([]);
262
267
  });
263
268
 
264
269
  it("highlights only the first recommended Product of a group", () => {
@@ -280,7 +285,7 @@ describe("offeringsPricing — periods, the switch and the fields (AC-2)", () =>
280
285
  it("maps yearly to annual and lands unit, note and terms note in their fields", () => {
281
286
  const growth = card(mapped(), "growth");
282
287
  // #12139 D1: annual mode shows the yearly Price per month.
283
- expect(growth.price).toEqual({ monthly: "M⟪$49", annual: "M⟪$40.83" });
288
+ expect(growth.price).toEqual({ monthly: "M⟪$49", annual: "M⟪$41" });
284
289
  expect(growth.priceUnit).toBe("per seat");
285
290
  expect(growth.priceSubhead).toBe("Billed per active seat");
286
291
  expect(growth.priceFootnote).toBe("Cancel any time from your account");
@@ -389,14 +394,14 @@ describe("offeringsPricing — periods, the switch and the fields (AC-2)", () =>
389
394
  expect(card(result, "growth").annualCtaHref).toBe(hrefFor("growth_yearly"));
390
395
  });
391
396
 
392
- it("formats an add-on tile's shown price and links its monthly Price", () => {
397
+ it("formats an add-on card's shown price and links its monthly Price", () => {
393
398
  const result = mapped();
394
- const seo = tile(result, "seo-audit");
395
- expect(seo.price).toBe("M⟪€19.50");
396
- expect(seo.qualifier).toBe("per site");
399
+ const seo = addonCard(result, "seo-audit");
400
+ expect(seo.price).toEqual({ monthly: "M⟪€19.50" });
401
+ expect(seo.priceUnit).toBe("per site");
397
402
  expect(seo.features).toEqual(["Monthly report"]);
398
403
  expect(seo.cta?.href).toBe(hrefFor("seo-audit_monthly"));
399
- expect(tile(result, "audit-pack").cta?.href).toBe(
404
+ expect(addonCard(result, "audit-pack").cta?.href).toBe(
400
405
  hrefFor("audit-pack_monthly"),
401
406
  );
402
407
  });
@@ -466,7 +471,7 @@ describe("offeringsPricing — a bundled plan links its required product (#10028
466
471
  expect(result.plans!.billingToggle).toBe(false);
467
472
  });
468
473
 
469
- it("renders no card for the required product itself, and keeps the add-on tile", () => {
474
+ it("renders no card for the required product itself, and keeps the add-on card", () => {
470
475
  const result = mapped(bundleSet());
471
476
  expect(plansOf(result).map((p) => p.key)).toEqual(["rebuild"]);
472
477
  expect(addonsOf(result).map((a) => a.key)).toEqual(["page"]);
@@ -525,7 +530,7 @@ describe("offeringsPricing — an offer is listed by neither fragment (#11166 AC
525
530
  edit(set);
526
531
  });
527
532
 
528
- it("maps the plans and add-ons exactly as without it; the offer gets no card and no tile", () => {
533
+ it("maps the plans and add-ons exactly as without it; the offer gets no card", () => {
529
534
  const result = mapped(withOffer());
530
535
  expect(plansOf(result).map((c) => c.key)).toEqual(plansOf(mapped()).map((c) => c.key));
531
536
  expect(addonsOf(result).map((t) => t.key)).toEqual(addonsOf(mapped()).map((t) => t.key));
@@ -591,10 +596,10 @@ describe("offeringsPricing — Stripe text stays text; every link is ours (AC-3)
591
596
  priceSubhead: "noteone",
592
597
  priceFootnote: "Terms",
593
598
  });
594
- expect(tile(result, "seo-audit")).toMatchObject({
599
+ expect(addonCard(result, "seo-audit")).toMatchObject({
595
600
  name: "SEO audit",
596
601
  features: ["Monthly report"],
597
- qualifier: "per site",
602
+ priceUnit: "per site",
598
603
  });
599
604
  });
600
605
 
@@ -607,9 +612,11 @@ describe("offeringsPricing — Stripe text stays text; every link is ours (AC-3)
607
612
  if (plan.annualCtaHref)
608
613
  links.push({ plan: plan.key!, href: plan.annualCtaHref });
609
614
  }
610
- for (const t of addonsOf(result))
611
- links.push({ plan: t.key, href: t.cta!.href });
612
- expect(links).toHaveLength(6);
615
+ for (const t of addonsOf(result)) {
616
+ links.push({ plan: t.key!, href: t.cta.href });
617
+ if (t.annualCtaHref) links.push({ plan: t.key!, href: t.annualCtaHref });
618
+ }
619
+ expect(links).toHaveLength(7);
613
620
 
614
621
  for (const { plan, href } of links) {
615
622
  const match = /^\/api\/offerings\/checkout\/(.+)$/.exec(href);
@@ -706,8 +713,12 @@ describe("offeringsPricing — no copy of its own (AC-7)", () => {
706
713
  if (plan.annualPriceNote) visible.push(plan.annualPriceNote);
707
714
  }
708
715
  for (const t of addonsOf(result)) {
709
- visible.push(t.cta!.label, t.price);
716
+ visible.push(
717
+ t.cta.label,
718
+ ...Object.values(t.price).filter((p): p is string => p !== undefined),
719
+ );
710
720
  if (t.eyebrow) visible.push(t.eyebrow);
721
+ if (t.annualPriceNote) visible.push(t.annualPriceNote);
711
722
  }
712
723
  for (const text of visible) expect(text).toContain("⟪");
713
724
 
@@ -755,7 +766,7 @@ describe("offeringsPricing — an offering page's `plans` (#10044 D4, AC-3)", ()
755
766
  );
756
767
  });
757
768
 
758
- it("keeps only the listed plan card and the listed add-on tile", () => {
769
+ it("keeps only the listed plan card and the listed add-on card", () => {
759
770
  const result = narrowed(shownSet(), ["growth", "audit-pack"]);
760
771
  expect(plansOf(result).map((p) => p.key)).toEqual(["growth"]);
761
772
  expect(addonsOf(result).map((a) => a.key)).toEqual(["audit-pack"]);
@@ -843,7 +854,7 @@ describe("offeringsPricing — the seller's button label (#12103 D1, AC-1)", ()
843
854
  expect(card(result, "growth").cta?.label).toBe(LABELS.cta);
844
855
  });
845
856
 
846
- it("labels an add-on tile and a bundle card with their own ctaLabel, the bundle href unchanged", () => {
857
+ it("labels an add-on card and a bundle card with their own ctaLabel, the bundle href unchanged", () => {
847
858
  const result = mapped(
848
859
  set([
849
860
  product("retainer", "plan", monthly("retainer")),
@@ -858,7 +869,7 @@ describe("offeringsPricing — the seller's button label (#12103 D1, AC-1)", ()
858
869
  label: "Start the bundle",
859
870
  href: offeringsBundleHref("setup_once", "retainer_monthly"),
860
871
  });
861
- expect(tile(result, "seo").cta?.label).toBe("Add it");
872
+ expect(addonCard(result, "seo").cta?.label).toBe("Add it");
862
873
  });
863
874
 
864
875
  it("removes a right-to-left override from the label and renders it as the button's text, linking the checkout path", () => {
@@ -895,18 +906,18 @@ describe("offeringsPricing — the add-on eyebrow and note (#12103 D5, AC-4)", (
895
906
  });
896
907
  }
897
908
 
898
- it("maps the eyebrow, the note and the unit label to their own tile fields", () => {
899
- expect(tile(mapped(set([seo({})])), "seo")).toMatchObject({
909
+ it("maps the eyebrow, the note and the unit label to their own card fields", () => {
910
+ expect(addonCard(mapped(set([seo({})])), "seo")).toMatchObject({
900
911
  eyebrow: "No retainer",
901
- note: "Per piece.",
902
- qualifier: "piece",
912
+ priceSubhead: "Per piece.",
913
+ priceUnit: "piece",
903
914
  });
904
915
  });
905
916
 
906
917
  it("keeps the Recommended label as the recommended add-on's eyebrow, its note kept", () => {
907
- expect(tile(mapped(set([seo({ recommended: true })])), "seo")).toMatchObject({
918
+ expect(addonCard(mapped(set([seo({ recommended: true })])), "seo")).toMatchObject({
908
919
  eyebrow: LABELS.recommended,
909
- note: "Per piece.",
920
+ priceSubhead: "Per piece.",
910
921
  });
911
922
  });
912
923
 
@@ -916,15 +927,15 @@ describe("offeringsPricing — the add-on eyebrow and note (#12103 D5, AC-4)", (
916
927
  expect(card(result, "growth")).not.toHaveProperty("note");
917
928
  });
918
929
 
919
- it("emits neither field on a tile whose product carries none", () => {
920
- const t = tile(mapped(), "audit-pack");
930
+ it("emits neither field on a card whose product carries none", () => {
931
+ const t = addonCard(mapped(), "audit-pack");
921
932
  expect(t).not.toHaveProperty("eyebrow");
922
- expect(t).not.toHaveProperty("note");
933
+ expect(t).not.toHaveProperty("priceSubhead");
923
934
  });
924
935
  });
925
936
 
926
937
  describe("offeringsPricing — exclude (#12103 D2)", () => {
927
- it("drops the excluded plans' cards and keeps every add-on tile", () => {
938
+ it("drops the excluded plans' cards and keeps every add-on card", () => {
928
939
  const result = offeringsPricing(shownSet(), { ...OPTIONS, exclude: ["growth"] })!;
929
940
  expect(plansOf(result).map((c) => c.key)).toEqual(["starter", "basic"]);
930
941
  expect(addonsOf(result).map((t) => t.key)).toEqual(["seo-audit", "audit-pack"]);
@@ -966,10 +977,11 @@ describe("offeringsPricing — the annual price per month (#12139 D1, AC-2)", ()
966
977
  expect(annual.annualCtaHref).toBe("/api/offerings/checkout/annual-plan_yearly");
967
978
  });
968
979
 
969
- it("rounds the per-month amount to the nearest minor unit", () => {
980
+ // #12193 D8 — whole currency units, was the nearest minor unit.
981
+ it("rounds the per-month amount to whole currency units", () => {
970
982
  const result = mapped(perMonthSet());
971
- expect(card(result, "odd-plan").price.annual).toBe("M⟪$40.83");
972
- expect(card(result, "round-up-plan").price.annual).toBe("M⟪$49.92");
983
+ expect(card(result, "odd-plan").price.annual).toBe("M⟪$41");
984
+ expect(card(result, "round-up-plan").price.annual).toBe("M⟪$50");
973
985
  expect(card(result, "whole-plan").price.annual).toBe("M⟪$10");
974
986
  expect(card(result, "yen-plan").price.annual).toBe("M⟪¥833");
975
987
  expect(card(result, "yen-plan").annualPriceNote).toBe("B⟪¥10,000");
@@ -1066,7 +1078,6 @@ describe("offeringsPricing — the terms note of a both-prices card is annual-on
1066
1078
 
1067
1079
  const LAYOUTS = [
1068
1080
  "three-tiers-with-toggle",
1069
- "with-comparison-table",
1070
1081
  "two-tiers-with-extra-tier",
1071
1082
  "single-price-with-details",
1072
1083
  "features-and-plans",
@@ -1080,7 +1091,7 @@ describe("offeringsPricing — one mapping per layout (#12140 D3, AC-1)", () =>
1080
1091
  );
1081
1092
  });
1082
1093
 
1083
- it.each(["with-comparison-table", "two-tiers-with-extra-tier", "band-hero"] as const)(
1094
+ it.each(["two-tiers-with-extra-tier", "band-hero"] as const)(
1084
1095
  "%s: centred cards, no billing toggle",
1085
1096
  (layout) => {
1086
1097
  const result = offeringsPricing(shownSet(), { ...OPTIONS, layout })!;
@@ -1092,10 +1103,11 @@ describe("offeringsPricing — one mapping per layout (#12140 D3, AC-1)", () =>
1092
1103
  },
1093
1104
  );
1094
1105
 
1095
- it("single-price-with-details: the first card only, no card layout and no toggle", () => {
1106
+ it("single-price-with-details: the first card only, no card layout, and a toggle only when that card has both periods (#12241 D5)", () => {
1096
1107
  const result = offeringsPricing(shownSet(), { ...OPTIONS, layout: "single-price-with-details" })!;
1097
1108
  expect(result.plans).toStrictEqual({
1098
1109
  variant: "single-price-with-details",
1110
+ billingToggle: false,
1099
1111
  plans: [plansOf(mapped())[0]],
1100
1112
  });
1101
1113
  expect(result.plans!.plans[0]!.key).toBe("starter");
@@ -1130,6 +1142,7 @@ describe("offeringsPricing — features-and-plans splits one product into two bl
1130
1142
  highlighted: true,
1131
1143
  highlightStyle: "pill",
1132
1144
  highlightLabel: "REC⟪",
1145
+ offerPrices: [{ amount: "49", currency: "USD", period: "month" }],
1133
1146
  },
1134
1147
  {
1135
1148
  key: "growth_yearly",
@@ -1140,6 +1153,7 @@ describe("offeringsPricing — features-and-plans splits one product into two bl
1140
1153
  priceUnit: "per seat",
1141
1154
  priceSubhead: "Billed per active seat",
1142
1155
  priceFootnote: "Cancel any time from your account",
1156
+ offerPrices: [{ amount: "490", currency: "USD", period: "year" }],
1143
1157
  },
1144
1158
  ],
1145
1159
  });
@@ -1192,7 +1206,7 @@ describe("offeringsPricing — no layout names a vendor; every link is ours (#12
1192
1206
  expect(JSON.stringify(result)).not.toMatch(/stripe/i);
1193
1207
  const links = [
1194
1208
  ...plansOf(result).flatMap((c) => [c.cta.href, ...(c.annualCtaHref ? [c.annualCtaHref] : [])]),
1195
- ...addonsOf(result).map((t) => t.cta?.href ?? ""),
1209
+ ...addonsOf(result).flatMap((t) => [t.cta.href, ...(t.annualCtaHref ? [t.annualCtaHref] : [])]),
1196
1210
  ];
1197
1211
  expect(links.length).toBeGreaterThan(0);
1198
1212
  for (const href of links) expect(href.startsWith(OFFERINGS_CHECKOUT_PATH)).toBe(true);
@@ -1316,3 +1330,1185 @@ describe("offeringsPricing — levelGroups (#12174 D6, AC-5)", () => {
1316
1330
  ]);
1317
1331
  });
1318
1332
  });
1333
+
1334
+ // ─── #12193 — cards built from Stripe ───────────────────────────────────────
1335
+
1336
+ /**
1337
+ * The spec's TIER_SET (§ 5): the three Individual plans as one tier of a
1338
+ * collection, a Team tier of one, an Essentials plan of another collection, an
1339
+ * SEO add-on, and two contacts — the Enterprise plan and the Commerce add-on.
1340
+ */
1341
+ function tierSet(
1342
+ edit: (offerings: OfferingsProduct[], contacts: OfferingsContactProduct[]) => void = () => {},
1343
+ ): WorkspaceShownSet {
1344
+ return shownSet((set) => {
1345
+ const meta = [
1346
+ { level: "Messaging", ailkOrder: 10, description: "Msg desc" },
1347
+ { level: "Playbooks", ailkOrder: 20, description: "PB desc" },
1348
+ { level: "Suite", ailkOrder: 30, description: null },
1349
+ ];
1350
+ const individual = levelSet().offerings.slice(-3).map((o, i) => ({
1351
+ ...o,
1352
+ collection: "growth-platform",
1353
+ tier: "Individual",
1354
+ ...meta[i]!,
1355
+ }));
1356
+ const offerings: OfferingsProduct[] = [
1357
+ ...individual,
1358
+ product("team-msg", "plan", [price("team-msg", "monthly", 44900, "usd"), price("team-msg", "yearly", 471600, "usd")], {
1359
+ collection: "growth-platform",
1360
+ tier: "Team",
1361
+ level: "Messaging",
1362
+ ailkOrder: 40,
1363
+ description: "Team desc",
1364
+ }),
1365
+ product("essentials", "plan", [price("essentials", "monthly", 9900, "usd")], {
1366
+ collection: "content-factory",
1367
+ shortName: "Essentials",
1368
+ name: "Content Factory - Essentials",
1369
+ }),
1370
+ product("seo", "addon", [price("seo", "once", 19900, "usd")], { collection: "growth-hub", shortName: "SEO" }),
1371
+ ];
1372
+ const contacts: OfferingsContactProduct[] = [
1373
+ {
1374
+ productId: "prod_enterprise",
1375
+ plan: "enterprise",
1376
+ ailkGroup: "plan",
1377
+ name: "Growth Platform Enterprise",
1378
+ description: null,
1379
+ marketingFeatures: ["Everything in Team"],
1380
+ ailkOrder: 50,
1381
+ url: "https://example.com/meet?x=1",
1382
+ ctaLabel: "Book a call",
1383
+ tier: "Enterprise",
1384
+ collection: "growth-platform",
1385
+ },
1386
+ {
1387
+ productId: "prod_commerce",
1388
+ plan: "commerce",
1389
+ ailkGroup: "addon",
1390
+ name: "Growth Hub Commerce",
1391
+ description: null,
1392
+ marketingFeatures: [],
1393
+ ailkOrder: null,
1394
+ url: "https://example.com/contact",
1395
+ ctaLabel: "Talk to us",
1396
+ priceText: "From 179 USD a month",
1397
+ shortName: "Commerce",
1398
+ collection: "growth-hub",
1399
+ },
1400
+ ];
1401
+ edit(offerings, contacts);
1402
+ set.offerings = offerings;
1403
+ set.productIds = offerings.map((o) => o.productId);
1404
+ set.recommended = { plan: null, addon: null };
1405
+ set.contacts = contacts;
1406
+ });
1407
+ }
1408
+
1409
+ const SITE = { siteOrigin: "https://example.com" };
1410
+ const tiers = (set: WorkspaceShownSet, extra: Record<string, unknown> = {}) =>
1411
+ offeringsPricing(set, { ...OPTIONS, ...SITE, tiers: true, ...extra })!;
1412
+
1413
+ describe("offeringsPricing — tier cards (#12193 D5, AC-2)", () => {
1414
+ it("groups a tier's plans into one level card titled by the tier, labelled and ordered from Stripe", () => {
1415
+ const cards = plansOf(tiers(tierSet(), { collection: "growth-platform" }));
1416
+ expect(cards.map((c) => c.key)).toEqual(["ind-msg", "team-msg", "enterprise"]);
1417
+ const individual = cards[0]!;
1418
+ expect(individual.name).toBe("Individual");
1419
+ expect(individual.levels!.map((l) => l.label)).toEqual(["Messaging", "Playbooks", "Suite"]);
1420
+ expect(individual.levels!.map((l) => l.key)).toEqual(["ind-msg", "ind-pb", "ind-suite"]);
1421
+ expect(individual.levels!.map((l) => l.description)).toEqual(["Msg desc", "PB desc", undefined]);
1422
+ expect(individual.levels![2]).not.toHaveProperty("description");
1423
+ expect(individual.description).toBe("Msg desc");
1424
+ const team = cards[1]!;
1425
+ expect(team.name).toBe("Team");
1426
+ expect(team).not.toHaveProperty("levels");
1427
+ });
1428
+
1429
+ it("orders the levels by ailk_order", () => {
1430
+ const set = tierSet((o) => {
1431
+ o.find((p) => p.plan === "ind-pb")!.ailkOrder = 5;
1432
+ });
1433
+ const individual = plansOf(tiers(set, { collection: "growth-platform" }))[0]!;
1434
+ expect(individual.levels!.map((l) => l.label)).toEqual(["Playbooks", "Messaging", "Suite"]);
1435
+ });
1436
+
1437
+ it("falls back to the short name or name for a repeated label, so the labels stay distinct", () => {
1438
+ const set = tierSet((o) => {
1439
+ o.find((p) => p.plan === "ind-pb")!.level = "Messaging";
1440
+ });
1441
+ const labels = plansOf(tiers(set, { collection: "growth-platform" }))[0]!.levels!.map((l) => l.label);
1442
+ expect(new Set(labels).size).toBe(labels.length);
1443
+ expect(labels[1]).toBe("Growth Platform Individual Playbooks");
1444
+ });
1445
+
1446
+ it("keeps at most four levels", () => {
1447
+ const set = tierSet((o) => {
1448
+ for (const n of [1, 2]) {
1449
+ o.push(
1450
+ product(`ind-x${n}`, "plan", [price(`ind-x${n}`, "monthly", 50000, "usd")], {
1451
+ collection: "growth-platform",
1452
+ tier: "Individual",
1453
+ level: `X${n}`,
1454
+ ailkOrder: 30 + n,
1455
+ }),
1456
+ );
1457
+ }
1458
+ });
1459
+ expect(plansOf(tiers(set, { collection: "growth-platform" }))[0]!.levels).toHaveLength(4);
1460
+ });
1461
+ });
1462
+
1463
+ describe("offeringsPricing — ailk_name titles a card (#12193 D5 rule 3, D6, AC-3)", () => {
1464
+ it("titles a plan with no tier by its short name, outside tier mode too; the snapshot keeps the Stripe name", () => {
1465
+ const set = tierSet();
1466
+ expect(card(offeringsPricing(set, { ...OPTIONS, plans: ["essentials"] })!, "essentials").name).toBe("Essentials");
1467
+ expect(offering(set, "essentials").name).toBe("Content Factory - Essentials");
1468
+ });
1469
+
1470
+ it("titles an add-on card by its short name", () => {
1471
+ expect(addonCard(offeringsPricing(tierSet(), OPTIONS)!, "seo").name).toBe("SEO");
1472
+ });
1473
+ });
1474
+
1475
+ describe("offeringsPricing — a collection (#12193 D5 rule 1, AC-4)", () => {
1476
+ it("shows every shown plan of the collection, compared lowercased, and no other", () => {
1477
+ const set = tierSet((o) => {
1478
+ for (const p of o) if (p.collection === "growth-platform") p.collection = "Growth-Platform";
1479
+ });
1480
+ const keys = plansOf(tiers(set, { collection: "growth-platform" })).map((c) => c.key);
1481
+ expect(keys).toEqual(["ind-msg", "team-msg", "enterprise"]);
1482
+ expect(keys).not.toContain("essentials");
1483
+ });
1484
+
1485
+ it("collectionPlans names the collection's plan slugs, contacts included", () => {
1486
+ expect(collectionPlans(tierSet(), "growth-platform")).toEqual(["ind-msg", "ind-pb", "ind-suite", "team-msg", "enterprise"]);
1487
+ expect(collectionPlans(tierSet(), "nothing")).toEqual([]);
1488
+ });
1489
+ });
1490
+
1491
+ describe("offeringsPricing — the contact card (#12193 D5 rule 7, AC-5, AC-6)", () => {
1492
+ const enterprise = (set = tierSet(), extra: Record<string, unknown> = {}) =>
1493
+ card(tiers(set, { collection: "growth-platform", ...extra }), "enterprise");
1494
+
1495
+ it("is a card in the same grid: tier title, translated Custom, the ailk_cta label and a same-site internal link", () => {
1496
+ expect(enterprise()).toEqual({
1497
+ key: "enterprise",
1498
+ name: "Enterprise",
1499
+ price: { custom: "C⟪" },
1500
+ cta: { label: "Book a call", href: "/meet?x=1" },
1501
+ features: ["Everything in Team"],
1502
+ offerPrices: [],
1503
+ });
1504
+ });
1505
+
1506
+ it("is an external link on another origin", () => {
1507
+ expect(enterprise(tierSet(), { siteOrigin: "https://other.test" }).cta).toEqual({
1508
+ label: "Book a call",
1509
+ href: "https://example.com/meet?x=1",
1510
+ external: true,
1511
+ });
1512
+ });
1513
+
1514
+ it("treats a same-origin path starting with // as external", () => {
1515
+ const set = tierSet((_o, c) => {
1516
+ c[0]!.url = "https://example.com//evil.test/x";
1517
+ });
1518
+ expect(enterprise(set).cta).toEqual({ label: "Book a call", href: "https://example.com//evil.test/x", external: true });
1519
+ });
1520
+
1521
+ it.each([
1522
+ ["a same-origin /api/ path", "https://example.com/API/offerings/checkout/a_monthly"],
1523
+ ["a percent-encoded /api/ path", "https://example.com/%61pi/offerings/checkout/a_monthly"],
1524
+ ["a path that does not percent-decode", "https://example.com/%zz"],
1525
+ ["the bare same-origin /api path", "https://example.com/api?x=1"],
1526
+ ])("gives no card for %s, and never throws", (_label, url) => {
1527
+ const set = tierSet((_o, c) => {
1528
+ c[0]!.url = url;
1529
+ });
1530
+ expect(plansOf(tiers(set, { collection: "growth-platform" })).map((c) => c.key)).not.toContain("enterprise");
1531
+ });
1532
+
1533
+ it("shows ailk_price_text in the price slot and publishes no priced Offer (AC-6)", () => {
1534
+ const set = tierSet((_o, c) => {
1535
+ c[0]!.priceText = "From 179 USD a month";
1536
+ });
1537
+ const contact = enterprise(set);
1538
+ expect(contact.price).toEqual({ custom: "From 179 USD a month" });
1539
+ expect((contact as { offerPrices?: unknown }).offerPrices).toEqual([]);
1540
+ });
1541
+
1542
+ it("is never highlighted, and appears in no section that names its plans or maps the page's plans", () => {
1543
+ expect(enterprise()).not.toHaveProperty("highlighted");
1544
+ const keys = (result: OfferingsPricing | null) => (result?.plans?.plans ?? []).map((c) => c.key);
1545
+ expect(keys(offeringsPricing(tierSet(), OPTIONS))).not.toContain("enterprise");
1546
+ expect(keys(offeringsPricing(tierSet(), { ...OPTIONS, ...SITE, tiers: true }))).not.toContain("enterprise");
1547
+ });
1548
+ });
1549
+
1550
+ describe("offeringsPricing — the add-on contact card (#12193 AC-7, #12241 D3)", () => {
1551
+ it("an add-ons collection shows the add-on and the contact card with its display price, label and link", () => {
1552
+ const addons = addonsOf(tiers(tierSet(), { collection: "growth-hub" }));
1553
+ expect(addons.map((t) => t.key)).toEqual(["seo", "commerce"]);
1554
+ expect(addons[0]!.name).toBe("SEO");
1555
+ expect(addons[1]).toEqual({
1556
+ key: "commerce",
1557
+ name: "Commerce",
1558
+ price: { custom: "From 179 USD a month" },
1559
+ features: [],
1560
+ cta: { label: "Talk to us", href: "/contact" },
1561
+ offerPrices: [],
1562
+ });
1563
+ });
1564
+ });
1565
+
1566
+ describe("offeringsPricing — whole dollars per month (#12193 D8, AC-12)", () => {
1567
+ const level = (set: WorkspaceShownSet, plan: string) =>
1568
+ plansOf(offeringsPricing(set, { ...OPTIONS, plans: LEVEL_PLANS, levelGroups: [INDIVIDUAL] })!)[0]!.levels!.find(
1569
+ (l) => l.key === plan,
1570
+ )!;
1571
+
1572
+ it("rounds a per-month price derived from a yearly price to whole dollars, keeping the exact yearly total", () => {
1573
+ expect(level(levelSet(), "ind-pb").price.annual).toBe("M⟪$256");
1574
+ expect(level(levelSet(), "ind-pb").annualPriceNote).toBe("B⟪$3,068");
1575
+ expect(level(levelSet(), "ind-msg").price.annual).toBe("M⟪$214");
1576
+ const cents = levelSet((o) =>
1577
+ o.map((p) =>
1578
+ p.plan === "ind-pb"
1579
+ ? { ...p, prices: p.prices.map((x) => (x.period === "yearly" ? { ...x, amount: 306850 } : x)) }
1580
+ : p,
1581
+ ),
1582
+ );
1583
+ expect(level(cents, "ind-pb").price.annual).toBe("M⟪$256");
1584
+ expect(level(cents, "ind-pb").annualPriceNote).toBe("B⟪$3,068.50");
1585
+ });
1586
+
1587
+ it("leaves a zero-decimal currency as it is", () => {
1588
+ const set = shownSet((s) => {
1589
+ s.offerings = [product("yen", "plan", [price("yen", "monthly", 1000, "jpy"), price("yen", "yearly", 10000, "jpy")])];
1590
+ s.productIds = ["prod_yen"];
1591
+ s.recommended = { plan: null, addon: null };
1592
+ });
1593
+ expect(card(offeringsPricing(set, OPTIONS)!, "yen").price.annual).toBe("M⟪¥833");
1594
+ });
1595
+ });
1596
+
1597
+ describe("offeringsPricing — offerPrices for the JSON-LD (#12193 D9, AC-13)", () => {
1598
+ it("carries each shown Price at full precision in major units, on a card and its level", () => {
1599
+ const result = offeringsPricing(levelSet(), { ...OPTIONS, plans: LEVEL_PLANS, levelGroups: [INDIVIDUAL] })!;
1600
+ const levels = plansOf(result)[0]!.levels! as Array<{ offerPrices?: unknown }>;
1601
+ expect(levels[0]!.offerPrices).toEqual([
1602
+ { amount: "249", currency: "USD", period: "month" },
1603
+ { amount: "2568", currency: "USD", period: "year" },
1604
+ ]);
1605
+ const plain = card(offeringsPricing(levelSet(), OPTIONS)!, "ind-pb") as { offerPrices?: unknown };
1606
+ expect(plain.offerPrices).toEqual([
1607
+ { amount: "299", currency: "USD", period: "month" },
1608
+ { amount: "3068", currency: "USD", period: "year" },
1609
+ ]);
1610
+ });
1611
+ });
1612
+
1613
+ describe("offeringsPricing — 0.76.0 sections render as before (#12193 AC-17)", () => {
1614
+ it("an offeringGroups card keeps its page title when its products carry a tier, and levels carry no description", () => {
1615
+ const set = levelSet((o) => o.map((p) => ({ ...p, tier: "Other", description: "Stripe desc" })));
1616
+ const c = plansOf(offeringsPricing(set, { ...OPTIONS, plans: LEVEL_PLANS, levelGroups: [INDIVIDUAL] })!)[0]!;
1617
+ expect(c.name).toBe("Individual");
1618
+ for (const l of c.levels!) expect(l).not.toHaveProperty("description");
1619
+ expect(c).not.toHaveProperty("description");
1620
+ });
1621
+
1622
+ it("a section naming its plans keeps one card per plan though they carry a tier", () => {
1623
+ const cards = plansOf(offeringsPricing(tierSet(), { ...OPTIONS, plans: ["ind-msg", "ind-pb"] })!);
1624
+ expect(cards.map((c) => c.key)).toEqual(["ind-msg", "ind-pb"]);
1625
+ for (const c of cards) expect(c).not.toHaveProperty("levels");
1626
+ });
1627
+
1628
+ it("no unbound mapping shows a contact", () => {
1629
+ const result = offeringsPricing(tierSet(), OPTIONS)!;
1630
+ expect(plansOf(result).map((c) => c.key)).not.toContain("enterprise");
1631
+ expect(addonsOf(result).map((t) => t.key)).not.toContain("commerce");
1632
+ });
1633
+ });
1634
+
1635
+ // ─── #12209 — helper text, twenty levels and separate tier cards ─────────────
1636
+
1637
+ describe("offeringsPricing — a plan's helper text becomes its level's (#12209 D5, AC-5)", () => {
1638
+ const helped = (set: WorkspaceShownSet, helpers: Record<string, string>) => {
1639
+ for (const o of set.offerings) if (helpers[o.plan] !== undefined) o.switchHelper = helpers[o.plan];
1640
+ return set;
1641
+ };
1642
+
1643
+ it("a tier's levels take their products' helpers; the card carries none", () => {
1644
+ const set = helped(tierSet(), { "ind-msg": "per brand", "ind-pb": "per team" });
1645
+ const individual = plansOf(tiers(set, { collection: "growth-platform" }))[0]!;
1646
+ expect(individual.levels!.map((l) => l.helper)).toEqual(["per brand", "per team", undefined]);
1647
+ expect(individual.levels![2]).not.toHaveProperty("helper");
1648
+ expect(individual).not.toHaveProperty("helper");
1649
+ expect(individual).not.toHaveProperty("levelHelper");
1650
+ });
1651
+
1652
+ it("an offeringGroups card's levels take their products' helpers; the card carries none", () => {
1653
+ const set = helped(levelSet(), { "ind-msg": "per brand" });
1654
+ const card = plansOf(grouped(set)!)[0]!;
1655
+ expect(card.levels![0]!.helper).toBe("per brand");
1656
+ expect(card.levels![1]).not.toHaveProperty("helper");
1657
+ expect(card).not.toHaveProperty("helper");
1658
+ expect(card).not.toHaveProperty("levelHelper");
1659
+ });
1660
+
1661
+ it("a lone plan's card carries none (the Admin preview's planCard is unchanged)", () => {
1662
+ const set = helped(levelSet(), { "ind-msg": "per brand" });
1663
+ const lone = card(offeringsPricing(set, { ...OPTIONS, plans: ["ind-msg"] })!, "ind-msg");
1664
+ expect(lone).not.toHaveProperty("helper");
1665
+ expect(lone).not.toHaveProperty("levelHelper");
1666
+ expect(JSON.stringify(lone)).not.toContain("per brand");
1667
+ });
1668
+ });
1669
+
1670
+ describe("offeringsPricing — an offeringGroups card's control (#12209 D2, AC-1)", () => {
1671
+ it("copies the group's levelSwitchControl onto its card, and sets none when the group sets none", () => {
1672
+ const withControl = plansOf(
1673
+ offeringsPricing(levelSet(), {
1674
+ ...OPTIONS,
1675
+ plans: LEVEL_PLANS,
1676
+ levelGroups: [{ ...INDIVIDUAL, levelSwitchControl: "select" as const }],
1677
+ })!,
1678
+ )[0]!;
1679
+ expect(withControl.levelSwitchControl).toBe("select");
1680
+ expect(plansOf(grouped(levelSet())!)[0]!).not.toHaveProperty("levelSwitchControl");
1681
+ });
1682
+ });
1683
+
1684
+ describe("offeringsPricing — the level limit (#12209 D8, AC-8)", () => {
1685
+ const twentyTwo = () =>
1686
+ tierSet((o) => {
1687
+ for (let n = 1; n <= 22; n++) {
1688
+ o.push(
1689
+ product(`ind-n${n}`, "plan", [price(`ind-n${n}`, "monthly", 1000 * n, "usd")], {
1690
+ collection: "big",
1691
+ tier: "Big",
1692
+ level: `N${n}`,
1693
+ ailkOrder: 100 + n,
1694
+ }),
1695
+ );
1696
+ }
1697
+ });
1698
+
1699
+ it("keeps twenty levels, in snapshot order, with levelLimit 20; four without it", () => {
1700
+ const twenty = plansOf(tiers(twentyTwo(), { collection: "big", levelLimit: 20 }))[0]!;
1701
+ expect(twenty.levels!.map((l) => l.label)).toEqual(Array.from({ length: 20 }, (_, i) => `N${i + 1}`));
1702
+ expect(plansOf(tiers(twentyTwo(), { collection: "big" }))[0]!.levels).toHaveLength(4);
1703
+ });
1704
+ });
1705
+
1706
+ describe("offeringsPricing — separate tier cards (#12209 D11, AC-9)", () => {
1707
+ it("groupTiers: false makes every plan its own card, titled by its own name, the collection and order kept", () => {
1708
+ const cards = plansOf(tiers(tierSet(), { collection: "growth-platform", groupTiers: false }));
1709
+ expect(cards.map((c) => c.key)).toEqual(["ind-msg", "ind-pb", "ind-suite", "team-msg", "enterprise"]);
1710
+ for (const c of cards) expect(c).not.toHaveProperty("levels");
1711
+ const first = offering(tierSet(), "ind-msg");
1712
+ expect(cards[0]!.name).toBe(first.shortName ?? first.name);
1713
+ expect(cards[0]!.name).not.toBe("Individual");
1714
+ });
1715
+
1716
+ it("without groupTiers, the tier is one card as before", () => {
1717
+ expect(tiers(tierSet(), { collection: "growth-platform", groupTiers: undefined })).toEqual(
1718
+ tiers(tierSet(), { collection: "growth-platform" }),
1719
+ );
1720
+ });
1721
+ });
1722
+
1723
+ describe("offeringsPricing — the yearly line stays the mapper's (#12209 D7, AC-7)", () => {
1724
+ it("sets billed-yearly beside both Prices and never on a monthly-only plan", () => {
1725
+ const set = shownSet((s) => {
1726
+ s.offerings = [
1727
+ product("both", "plan", [price("both", "monthly", 24900, "usd"), price("both", "yearly", 256800, "usd")]),
1728
+ product("month", "plan", [price("month", "monthly", 24900, "usd")]),
1729
+ ];
1730
+ s.productIds = s.offerings.map((o) => o.productId);
1731
+ s.recommended = { plan: null, addon: null };
1732
+ });
1733
+ const result = offeringsPricing(set, OPTIONS)!;
1734
+ expect(card(result, "both").annualPriceNote).toBe("B⟪$2,568");
1735
+ expect(card(result, "month")).not.toHaveProperty("annualPriceNote");
1736
+ });
1737
+ });
1738
+
1739
+ // ─── #12210 — several prices on one Stripe product ───────────────────────────
1740
+
1741
+ /** A monthly Price of one price point, with its normalized nickname. */
1742
+ function pointPrice(plan: string, amount: number, label?: string): OfferingsPrice {
1743
+ const p = price(plan, "monthly", amount, "usd");
1744
+ return label === undefined ? p : { ...p, label };
1745
+ }
1746
+
1747
+ /** Hire a Writer (spec § 5 `WRITER_SET`): one plan product, three monthly points. */
1748
+ function writer(extra: Partial<OfferingsProduct> = {}): OfferingsProduct {
1749
+ return product(
1750
+ "writer-4",
1751
+ "plan",
1752
+ [
1753
+ pointPrice("writer-4", 220000, "4 pieces/mo"),
1754
+ pointPrice("writer-8", 440000, "8 pieces/mo"),
1755
+ pointPrice("writer-12", 660000, "12 pieces/mo"),
1756
+ ],
1757
+ {
1758
+ productId: "prod_writer",
1759
+ name: "Hire a Writer",
1760
+ description: "Writing, done",
1761
+ marketingFeatures: ["Edited"],
1762
+ ...extra,
1763
+ },
1764
+ );
1765
+ }
1766
+
1767
+ function writerSet(edit: (offerings: OfferingsProduct[]) => OfferingsProduct[] | void = () => {}): WorkspaceShownSet {
1768
+ return shownSet((s) => {
1769
+ s.offerings = [writer()];
1770
+ s.offerings = edit(s.offerings) ?? s.offerings;
1771
+ s.productIds = s.offerings.map((o) => o.productId);
1772
+ s.recommended = { plan: null, addon: null };
1773
+ });
1774
+ }
1775
+
1776
+ /** A plan product with `n` monthly points `p-1` … `p-n`, labelled `P1` … `Pn`. */
1777
+ function pointsProduct(n: number, extra: Partial<OfferingsProduct> = {}): OfferingsProduct {
1778
+ return product(
1779
+ "p-1",
1780
+ "plan",
1781
+ Array.from({ length: n }, (_, i) => pointPrice(`p-${i + 1}`, 1000 * (i + 1), `P${i + 1}`)),
1782
+ { productId: "prod_points", name: "Points", ...extra },
1783
+ );
1784
+ }
1785
+
1786
+ describe("offeringsPricing — a product's price points are one card's levels (#12210 D6, AC-1)", () => {
1787
+ it("one card keyed by the first point, titled by the product, one level per point labelled by its nickname", () => {
1788
+ const cards = plansOf(mapped(writerSet()));
1789
+ expect(cards).toHaveLength(1);
1790
+ const c = cards[0]!;
1791
+ expect(c.key).toBe("writer-4");
1792
+ expect(c.name).toBe("Hire a Writer");
1793
+ expect(c.levels!.map((l) => l.key)).toEqual(["writer-4", "writer-8", "writer-12"]);
1794
+ expect(c.levels!.map((l) => l.label)).toEqual(["4 pieces/mo", "8 pieces/mo", "12 pieces/mo"]);
1795
+ });
1796
+
1797
+ it("each level's secondary label is its amount, the select item's detail", () => {
1798
+ const c = plansOf(mapped(writerSet()))[0]!;
1799
+ expect(c.levels!.map((l) => l.detail)).toEqual([
1800
+ LABELS.monthly("$2,200"),
1801
+ LABELS.monthly("$4,400"),
1802
+ LABELS.monthly("$6,600"),
1803
+ ]);
1804
+ expect(c).not.toHaveProperty("detail");
1805
+ });
1806
+
1807
+ it("a point with no nickname is labelled by its price phrase, with no detail repeating it", () => {
1808
+ const set = writerSet(([w]) => [
1809
+ { ...w!, prices: w!.prices.map(({ label, ...p }) => (p.plan === "writer-8" ? p : { ...p, label: label! })) },
1810
+ ]);
1811
+ const level = plansOf(mapped(set))[0]!.levels![1]!;
1812
+ expect(level.label).toBe(LABELS.monthly("$4,400"));
1813
+ expect(level).not.toHaveProperty("detail");
1814
+ });
1815
+
1816
+ it("a repeated nickname falls back to the price phrase, so the labels stay distinct", () => {
1817
+ const set = writerSet(([w]) => [{ ...w!, prices: w!.prices.map((p) => ({ ...p, label: "Same" })) }]);
1818
+ expect(plansOf(mapped(set))[0]!.levels!.map((l) => l.label)).toEqual([
1819
+ "Same",
1820
+ LABELS.monthly("$4,400"),
1821
+ LABELS.monthly("$6,600"),
1822
+ ]);
1823
+ });
1824
+
1825
+ it("the mapped section parses with the section schema", () => {
1826
+ expect(PricingSectionDataSchema.safeParse(mapped(writerSet()).plans).success).toBe(true);
1827
+ });
1828
+ });
1829
+
1830
+ describe("offeringsPricing — changing points changes the amount and the link only (#12210 D6 rule 1, AC-2)", () => {
1831
+ it("levels differ only in price, links, offerPrices, key, label and detail", () => {
1832
+ const levels = plansOf(mapped(writerSet()))[0]!.levels!;
1833
+ const rest = levels.map((level) => {
1834
+ const {
1835
+ price: _p,
1836
+ annualCtaHref: _a,
1837
+ annualPriceNote: _n,
1838
+ offerPrices: _o,
1839
+ priceParts: _pp,
1840
+ key: _k,
1841
+ label: _l,
1842
+ detail: _d,
1843
+ cta,
1844
+ ...fields
1845
+ } = level as typeof level & { offerPrices?: unknown; priceParts?: unknown };
1846
+ return { ...fields, cta: { label: cta.label } };
1847
+ });
1848
+ expect(rest[1]).toEqual(rest[0]);
1849
+ expect(rest[2]).toEqual(rest[0]);
1850
+ expect(rest[0]).toMatchObject({ description: "Writing, done", features: ["Edited"] });
1851
+ expect(levels.map((l) => l.cta.href)).toEqual([
1852
+ hrefFor("writer-4_monthly"),
1853
+ hrefFor("writer-8_monthly"),
1854
+ hrefFor("writer-12_monthly"),
1855
+ ]);
1856
+ expect(levels.map((l) => l.price.monthly)).toEqual([
1857
+ LABELS.monthly("$2,200"),
1858
+ LABELS.monthly("$4,400"),
1859
+ LABELS.monthly("$6,600"),
1860
+ ]);
1861
+ });
1862
+ });
1863
+
1864
+ describe("offeringsPricing — a tier mixes products and price points (#12210 D6 rule 4, AC-3)", () => {
1865
+ const mixed = (editorOrder: number) =>
1866
+ writerSet(([w]) => [
1867
+ { ...w!, tier: "Writing", ailkOrder: 10 },
1868
+ product("editor", "plan", [price("editor", "monthly", 150000, "usd")], {
1869
+ tier: "Writing",
1870
+ ailkOrder: editorOrder,
1871
+ description: "Editing only",
1872
+ marketingFeatures: ["One editor"],
1873
+ }),
1874
+ ]);
1875
+
1876
+ it("one card titled by the tier, the points in product then point order, each with its own product's text", () => {
1877
+ const cards = plansOf(tiers(mixed(20)));
1878
+ expect(cards).toHaveLength(1);
1879
+ const c = cards[0]!;
1880
+ expect(c.name).toBe("Writing");
1881
+ expect(c.levels!.map((l) => l.key)).toEqual(["writer-4", "writer-8", "writer-12", "editor"]);
1882
+ expect(c.levels!.map((l) => l.description)).toEqual(["Writing, done", "Writing, done", "Writing, done", "Editing only"]);
1883
+ expect(c.levels!.map((l) => l.features)).toEqual([["Edited"], ["Edited"], ["Edited"], ["One editor"]]);
1884
+ expect(c.levels![3]).not.toHaveProperty("detail");
1885
+ });
1886
+
1887
+ it("orders the members by ailk_order, keeping a product's points together", () => {
1888
+ expect(plansOf(tiers(mixed(5)))[0]!.levels!.map((l) => l.key)).toEqual([
1889
+ "editor",
1890
+ "writer-4",
1891
+ "writer-8",
1892
+ "writer-12",
1893
+ ]);
1894
+ });
1895
+ });
1896
+
1897
+ describe("offeringsPricing — a price added in Stripe is a level (#12210 AC-4)", () => {
1898
+ it("a fourth point gives a fourth level, with no page input changed", () => {
1899
+ const set = writerSet(([w]) => [{ ...w!, prices: [...w!.prices, pointPrice("writer-16", 880000, "16 pieces/mo")] }]);
1900
+ const c = plansOf(mapped(set))[0]!;
1901
+ expect(c.levels!.map((l) => l.key)).toEqual(["writer-4", "writer-8", "writer-12", "writer-16"]);
1902
+ });
1903
+ });
1904
+
1905
+ describe("offeringsPricing — twenty price points (#12210 D6 rule 6, AC-5)", () => {
1906
+ it("one card with twenty levels on the select control, each with its own checkout link", () => {
1907
+ const set = writerSet(() => [pointsProduct(20)]);
1908
+ const c = plansOf(mapped(set))[0]!;
1909
+ expect(c.levels).toHaveLength(20);
1910
+ expect(c.levelSwitchControl).toBe("select");
1911
+ expect(new Set(c.levels!.map((l) => l.cta.href)).size).toBe(20);
1912
+ expect(c.levels![19]!.cta.href).toBe(hrefFor("p-20_monthly"));
1913
+ expect(PricingSectionDataSchema.safeParse(mapped(set).plans).success).toBe(true);
1914
+ });
1915
+
1916
+ it("a card of four points follows the section's control", () => {
1917
+ const c = plansOf(mapped(writerSet(() => [pointsProduct(4)])))[0]!;
1918
+ expect(c.levels).toHaveLength(4);
1919
+ expect(c).not.toHaveProperty("levelSwitchControl");
1920
+ });
1921
+ });
1922
+
1923
+ describe("offeringsPricing — a one-point product is exactly as before (#12210 AC-6)", () => {
1924
+ it("its card has no levels, no detail and no control", () => {
1925
+ const growth = card(mapped(), "growth");
1926
+ expect(growth).not.toHaveProperty("levels");
1927
+ expect(growth).not.toHaveProperty("levelSwitchControl");
1928
+ expect(JSON.stringify(mapped())).not.toContain('"detail"');
1929
+ });
1930
+ });
1931
+
1932
+ describe("offeringsPricing — a product is named by any of its slugs (#12210 D6 rules 7–8)", () => {
1933
+ it("a page naming a later point keeps the product; excluding one drops it", () => {
1934
+ const set = writerSet((o) => [...o, ...fixtureOfferings().filter((p) => p.plan === "growth")]);
1935
+ expect(plansOf(offeringsPricing(set, { ...OPTIONS, plans: ["writer-8"] })!).map((c) => c.key)).toEqual(["writer-4"]);
1936
+ expect(plansOf(offeringsPricing(set, { ...OPTIONS, exclude: ["writer-12"] })!).map((c) => c.key)).toEqual(["growth"]);
1937
+ });
1938
+
1939
+ it("an offeringGroups level names one point", () => {
1940
+ const result = offeringsPricing(writerSet(), {
1941
+ ...OPTIONS,
1942
+ plans: ["writer-8", "writer-12"],
1943
+ levelGroups: [
1944
+ {
1945
+ key: "writers",
1946
+ name: "Writers",
1947
+ levels: [
1948
+ { label: "Eight", plan: "writer-8" },
1949
+ { label: "Twelve", plan: "writer-12" },
1950
+ ],
1951
+ },
1952
+ ],
1953
+ })!;
1954
+ const c = plansOf(result)[0]!;
1955
+ expect(c.levels!.map((l) => [l.label, l.cta.href])).toEqual([
1956
+ ["Eight", hrefFor("writer-8_monthly")],
1957
+ ["Twelve", hrefFor("writer-12_monthly")],
1958
+ ]);
1959
+ });
1960
+
1961
+ it("a bundle whose required product has points gives no card", () => {
1962
+ const set = writerSet((o) => [
1963
+ ...o,
1964
+ product("kickoff", "plan", [price("kickoff", "once", 50000, "usd")], { requires: "writer-8" }),
1965
+ ]);
1966
+ // The required product is sold only inside its bundle (#10028 decision 6),
1967
+ // and the bundle sells no ambiguous recurring Price — so neither shows.
1968
+ expect(mapped(set).plans).toBeNull();
1969
+ });
1970
+
1971
+ it("features-and-plans never splits a lone card with levels", () => {
1972
+ const set = writerSet(([w]) => [
1973
+ { ...w!, prices: [...w!.prices.slice(0, 1), { ...price("writer-4", "yearly", 2200000, "usd"), label: "4 pieces/mo" }, ...w!.prices.slice(1)] },
1974
+ ]);
1975
+ const plans = offeringsPricing(set, { ...OPTIONS, layout: "features-and-plans" })!.plans!.plans;
1976
+ expect(plans).toHaveLength(1);
1977
+ expect(plans[0]!.levels).toHaveLength(3);
1978
+ });
1979
+ });
1980
+
1981
+ describe("offeringsPricing — a twenty-one-level tier keeps twenty (#12210 D6 rule 6, AC-8)", () => {
1982
+ it("drops the twenty-first level, so no level names it", () => {
1983
+ const set = writerSet(() => [
1984
+ product("solo", "plan", [price("solo", "monthly", 500, "usd")], { tier: "Big", ailkOrder: 1 }),
1985
+ pointsProduct(20, { tier: "Big", ailkOrder: 2 }),
1986
+ ]);
1987
+ const cards = plansOf(tiers(set));
1988
+ expect(cards).toHaveLength(1);
1989
+ const keys = cards[0]!.levels!.map((l) => l.key);
1990
+ expect(keys).toHaveLength(20);
1991
+ expect(keys[19]).toBe("p-19");
1992
+ expect(keys).not.toContain("p-20");
1993
+ expect(cards[0]!.levelSwitchControl).toBe("select");
1994
+ });
1995
+ });
1996
+
1997
+ describe("price points under offeringGroups and in a long tier (#12210 D6 rules 4–6, D12)", () => {
1998
+ it("a group naming later points of the Recommended product is highlighted", () => {
1999
+ const set = writerSet((offerings) => [writer({ recommended: true }), ...offerings.slice(1)]);
2000
+ const groups = [
2001
+ { key: "writing", name: "Writing", levels: [{ label: "Eight", plan: "writer-8" }, { label: "Twelve", plan: "writer-12" }] },
2002
+ { key: "solo", name: "Solo", levels: [{ label: "Twelve", plan: "writer-12" }, { label: "Four", plan: "writer-4" }] },
2003
+ ];
2004
+ const cards = plansOf(offeringsPricing(set, { ...OPTIONS, levelGroups: groups })!);
2005
+ expect(cards.map((c) => [c.key, c.highlighted === true])).toEqual([
2006
+ ["writing", true],
2007
+ ["solo", true],
2008
+ ]);
2009
+ expect(cards[0]!.levels!.map((l) => l.key)).toEqual(["writer-8", "writer-12"]);
2010
+ });
2011
+
2012
+ it("a tier with a multi-point member keeps every member, up to 20 levels, on the select", () => {
2013
+ const tierOf = (n: number) =>
2014
+ product(`member-${n}`, "plan", [price(`member-${n}`, "monthly", 1000 * n, "usd")], { tier: "Writing", ailkOrder: 20 + n });
2015
+ const set = writerSet(() => [writer({ tier: "Writing", ailkOrder: 10 }), tierOf(1), tierOf(2), tierOf(3), tierOf(4)]);
2016
+ const card = plansOf(offeringsPricing(set, { ...OPTIONS, tiers: true })!)[0]!;
2017
+ expect(card.levels!.map((l) => l.key)).toEqual([
2018
+ "writer-4",
2019
+ "writer-8",
2020
+ "writer-12",
2021
+ "member-1",
2022
+ "member-2",
2023
+ "member-3",
2024
+ "member-4",
2025
+ ]);
2026
+ expect(card.levelSwitchControl).toBe("select");
2027
+ });
2028
+ });
2029
+
2030
+ // ─── #12238 — a collection of contacts, and a contact named by its slug ─────
2031
+
2032
+ describe("offeringsPricing — a collection whose only members are contacts (#12238)", () => {
2033
+ /** `tierSet()` with no priced product: the two contacts alone, both of `growth-hub`. */
2034
+ const contactsOnly = () =>
2035
+ tierSet((o, c) => {
2036
+ o.length = 0;
2037
+ for (const contact of c) contact.collection = "growth-hub";
2038
+ });
2039
+
2040
+ it("maps the plan contact to a card and the add-on contact to a tile, with no priced product shown", () => {
2041
+ const result = tiers(contactsOnly(), { collection: "growth-hub" });
2042
+ expect(plansOf(result).map((c) => c.key)).toEqual(["enterprise"]);
2043
+ expect(card(result, "enterprise")).toMatchObject({ name: "Enterprise", cta: { label: "Book a call", href: "/meet?x=1" } });
2044
+ expect(addonsOf(result).map((t) => t.key)).toEqual(["commerce"]);
2045
+ });
2046
+
2047
+ it("is null for the page-level mapping, which shows no contact", () => {
2048
+ expect(offeringsPricing(contactsOnly(), OPTIONS)).toBeNull();
2049
+ });
2050
+ });
2051
+
2052
+ describe("offeringsPricing — contactPlans names a contact by its slug (#12238, operator 2026-11-23)", () => {
2053
+ it("a named plan contact is a card after the named plans, and a named add-on contact a tile", () => {
2054
+ const result = offeringsPricing(tierSet(), {
2055
+ ...OPTIONS,
2056
+ ...SITE,
2057
+ plans: ["essentials", "enterprise", "commerce"],
2058
+ contactPlans: ["essentials", "enterprise", "commerce"],
2059
+ })!;
2060
+ expect(plansOf(result).map((c) => c.key)).toEqual(["essentials", "enterprise"]);
2061
+ expect(card(result, "enterprise")).toMatchObject({ name: "Enterprise", price: { custom: "C⟪" }, offerPrices: [] });
2062
+ expect(addonsOf(result).map((t) => t.key)).toEqual(["commerce"]);
2063
+ });
2064
+
2065
+ it("a contact it does not name stays out, and `plans` alone names no contact", () => {
2066
+ const keys = (extra: Record<string, unknown>) =>
2067
+ plansOf(offeringsPricing(tierSet(), { ...OPTIONS, ...SITE, plans: ["essentials", "enterprise"], ...extra })!).map((c) => c.key);
2068
+ expect(keys({ contactPlans: ["essentials"] })).toEqual(["essentials"]);
2069
+ expect(keys({})).toEqual(["essentials"]);
2070
+ });
2071
+
2072
+ it("a collection wins: contactPlans is not read beside it", () => {
2073
+ // `growth-hub` holds no plan, so the named plan contact gives no plans fragment.
2074
+ const result = tiers(tierSet(), { collection: "growth-hub", contactPlans: ["enterprise"] });
2075
+ expect(result.plans).toBeNull();
2076
+ expect(addonsOf(result).map((t) => t.key)).toEqual(["seo", "commerce"]);
2077
+ });
2078
+ });
2079
+
2080
+ describe("offeringsPricing — a plan's footnote and its link (#12243)", () => {
2081
+ const LINK = { label: "Learn more", url: "https://example.com/onboarding?x=1#fee" };
2082
+ const noted = (set: WorkspaceShownSet, plans: string[], link: typeof LINK | undefined = LINK) => {
2083
+ for (const o of set.offerings) {
2084
+ if (!plans.includes(o.plan)) continue;
2085
+ o.footnote = "*Cost shown​ excludes onboarding.";
2086
+ if (link) o.footnoteLink = link;
2087
+ }
2088
+ return workspaceShownSetSchema.parse(set);
2089
+ };
2090
+
2091
+ it("puts it on the plan's card, its format characters stripped, the link after it", () => {
2092
+ const growth = card(mapped(noted(shownSet(), ["growth"])), "growth");
2093
+ expect(growth.footnote).toBe("*Cost shown excludes onboarding.");
2094
+ expect(growth.footnoteLink).toEqual({ label: "Learn more", href: "https://example.com/onboarding?x=1#fee" });
2095
+ });
2096
+
2097
+ it("a same-origin URL is an internal path, another origin's the full URL", () => {
2098
+ const set = noted(tierSet(), ["team-msg"]);
2099
+ expect(card(tiers(set, { collection: "growth-platform" }), "team-msg").footnoteLink).toEqual({
2100
+ label: "Learn more",
2101
+ href: "/onboarding?x=1#fee",
2102
+ });
2103
+ expect(
2104
+ card(tiers(set, { collection: "growth-platform", siteOrigin: "https://other.test" }), "team-msg").footnoteLink,
2105
+ ).toEqual({ label: "Learn more", href: "https://example.com/onboarding?x=1#fee" });
2106
+ });
2107
+
2108
+ it.each([
2109
+ ["a same-origin /api/ path", "https://example.com/api/offerings/checkout/a_monthly"],
2110
+ ["a percent-encoded /api/ path", "https://example.com/%61pi/offerings/checkout/a_monthly"],
2111
+ ["a path that does not percent-decode", "https://example.com/%zz"],
2112
+ ])("drops the link for %s and keeps the footnote as text alone", (_label, url) => {
2113
+ const set = noted(tierSet(), ["team-msg"], { label: "Learn more", url });
2114
+ const team = card(tiers(set, { collection: "growth-platform" }), "team-msg");
2115
+ expect(team.footnote).toBe("*Cost shown excludes onboarding.");
2116
+ expect(team).not.toHaveProperty("footnoteLink");
2117
+ });
2118
+
2119
+ it("a card without one keeps exactly its earlier fields", () => {
2120
+ const before = card(mapped(), "growth");
2121
+ expect(before).not.toHaveProperty("footnote");
2122
+ expect(before).not.toHaveProperty("footnoteLink");
2123
+ expect(card(mapped(noted(shownSet(), ["basic"])), "growth")).toEqual(before);
2124
+ });
2125
+
2126
+ it("a tier card takes its first level's footnote, as its other card fields", () => {
2127
+ const set = noted(tierSet(), ["ind-msg"]);
2128
+ const individual = plansOf(tiers(set, { collection: "growth-platform" }))[0]!;
2129
+ expect(individual.footnote).toBe("*Cost shown excludes onboarding.");
2130
+ expect(individual.levels!.some((l) => "footnote" in l)).toBe(false);
2131
+ });
2132
+
2133
+ it("an offeringGroups card takes its first level's footnote", () => {
2134
+ const set = noted(levelSet(), ["ind-msg"]);
2135
+ const grouped0 = plansOf(grouped(set)!)[0]!;
2136
+ expect(grouped0.footnote).toBe("*Cost shown excludes onboarding.");
2137
+ expect(grouped0.levels!.some((l) => "footnote" in l)).toBe(false);
2138
+ });
2139
+
2140
+ it("a bundle card takes the plan's own footnote", () => {
2141
+ const set = shownSet((s) => {
2142
+ s.offerings.push(
2143
+ product("build", "plan", [price("build", "once", 300000, "usd")], {
2144
+ requires: "growth",
2145
+ footnote: "*Balance on delivery.",
2146
+ }),
2147
+ );
2148
+ s.productIds = s.offerings.map((o) => o.productId);
2149
+ });
2150
+ expect(card(mapped(set), "build").footnote).toBe("*Balance on delivery.");
2151
+ });
2152
+
2153
+ it("a plan contact's card carries its footnote", () => {
2154
+ const set = tierSet((_o, c) => {
2155
+ c[0]!.footnote = "*Annual contract.";
2156
+ c[0]!.footnoteLink = { label: "Terms", url: "https://example.com/terms" };
2157
+ });
2158
+ const contact = card(tiers(set, { collection: "growth-platform" }), "enterprise");
2159
+ expect(contact.footnote).toBe("*Annual contract.");
2160
+ expect(contact.footnoteLink).toEqual({ label: "Terms", href: "/terms" });
2161
+ });
2162
+
2163
+ it("the section schema accepts the cards and the tier card renders the footnote and its link", () => {
2164
+ const result = mapped(noted(shownSet(), ["growth"]));
2165
+ expect(PricingSectionDataSchema.safeParse(result.plans).success).toBe(true);
2166
+ const { getByTestId } = render(
2167
+ React.createElement(Pricing, { sectionName: "pricing", data: result.plans! } as Parameters<typeof Pricing>[0]),
2168
+ );
2169
+ expect(getByTestId("tier-footnote")).toHaveTextContent("*Cost shown excludes onboarding. Learn more");
2170
+ });
2171
+ });
2172
+
2173
+ // ─── #12239 — a Stripe price can be marked not public ─────────────────────────
2174
+ //
2175
+ // End-of-chain evidence only: the normalizer leaves a not-public Price out of
2176
+ // the shown set (packages/api's catalog and wire suites), so the mapper — which
2177
+ // is unchanged — sees the one-point product and draws a plain card.
2178
+
2179
+ describe("offeringsPricing — a product left with one public price is a plain card (#12239 AC-1, AC-4)", () => {
2180
+ it("the fixture's Growth card has no levels and no level control", () => {
2181
+ const growth = card(mapped(), "growth");
2182
+ expect(growth).not.toHaveProperty("levels");
2183
+ expect(growth).not.toHaveProperty("levelSwitchControl");
2184
+ });
2185
+
2186
+ it("the shape the pin's normalizer wrote for an unmarked partner Price is a level card, so the plain card is the filter's", () => {
2187
+ const set = shownSet((s) => {
2188
+ const growth = s.offerings.find((o) => o.plan === "growth")!;
2189
+ growth.plan = "growth-partner";
2190
+ growth.prices = [{ ...price("growth-partner", "monthly", 2900, "usd"), label: "Partner" }, ...growth.prices];
2191
+ });
2192
+ const growth = plansOf(mapped(set)).find((c) => c.levels?.some((l) => l.key === "growth-partner"));
2193
+ expect(growth).toBeDefined();
2194
+ expect(growth!.levels!.map((l) => l.key)).toEqual(["growth-partner", "growth"]);
2195
+ });
2196
+
2197
+ it("one public monthly Price, its not-public siblings left out upstream, maps to one plain card", () => {
2198
+ const set = shownSet((s) => {
2199
+ s.offerings = [product("growth", "plan", [price("growth", "monthly", 4900, "usd")])];
2200
+ s.productIds = ["prod_growth"];
2201
+ s.recommended = { plan: null, addon: null };
2202
+ });
2203
+ const cards = plansOf(mapped(set));
2204
+ expect(cards.map((c) => c.key)).toEqual(["growth"]);
2205
+ expect(cards[0]).not.toHaveProperty("levels");
2206
+ expect(cards[0]).not.toHaveProperty("levelSwitchControl");
2207
+ });
2208
+ });
2209
+
2210
+ // ─── #12246 — a comparison table's plan columns (spec 12246 D3, AC-1, AC-4) ──
2211
+
2212
+ describe("offeringsPlanColumns — a plan column's facts, from the shown set (#12246 D3)", () => {
2213
+ const S3_LABELS: OfferingsPricingLabels = {
2214
+ ...LABELS,
2215
+ monthly: (amount) => amount + "/mo",
2216
+ annual: (amount) => amount + "/yr",
2217
+ };
2218
+ const S3_OPTIONS = { locale: "en-US", labels: S3_LABELS };
2219
+ const both = (plan: string, monthly: number, yearly: number) => [
2220
+ price(plan, "monthly", monthly, "usd"),
2221
+ price(plan, "yearly", yearly, "usd"),
2222
+ ];
2223
+ function s3(edit: (offerings: OfferingsProduct[]) => void = () => {}): WorkspaceShownSet {
2224
+ const offerings = [
2225
+ product("essentials", "plan", both("essentials", 220000, 2376000)),
2226
+ product("growth", "plan", both("growth", 440000, 4752000), {
2227
+ shortName: "Growth",
2228
+ name: "Growth plan",
2229
+ recommended: true,
2230
+ }),
2231
+ product("scale", "plan", both("scale", 650000, 7020000)),
2232
+ product("extra", "addon", [price("extra", "monthly", 9900, "usd")]),
2233
+ ];
2234
+ edit(offerings);
2235
+ return shownSet((set) => {
2236
+ set.offerings = offerings;
2237
+ set.productIds = offerings.map((o) => o.productId);
2238
+ set.recommended = { plan: "prod_growth", addon: null };
2239
+ });
2240
+ }
2241
+
2242
+ it("AC-1: maps exactly the shown plan slugs, each as its card would show it", () => {
2243
+ const columns = offeringsPlanColumns(s3(), ["growth", "extra", "ghost"], S3_OPTIONS);
2244
+ expect([...columns.keys()]).toEqual(["growth"]);
2245
+ expect(columns.get("growth")).toEqual({
2246
+ name: "Growth",
2247
+ price: { monthly: "$4,400/mo", annual: "$3,960/mo" },
2248
+ cta: { label: LABELS.cta, href: `${OFFERINGS_CHECKOUT_PATH}/growth_monthly` },
2249
+ annualCtaHref: `${OFFERINGS_CHECKOUT_PATH}/growth_yearly`,
2250
+ recommended: true,
2251
+ });
2252
+ });
2253
+
2254
+ it("marks only the shown set's first Recommended plan, and reads no page plans", () => {
2255
+ const columns = offeringsPlanColumns(s3(), ["essentials", "growth", "scale"], S3_OPTIONS);
2256
+ expect([...columns.keys()]).toEqual(["essentials", "growth", "scale"]);
2257
+ expect([...columns.values()].filter((c) => c.recommended).map((c) => c.name)).toEqual(["Growth"]);
2258
+ expect(columns.get("essentials")).not.toHaveProperty("recommended");
2259
+ });
2260
+
2261
+ it("AC-4: resolves nothing from a set that is not current, or does not parse", () => {
2262
+ const stale = { ...s3(), state: "expired" };
2263
+ expect(offeringsPlanColumns(stale, ["growth"], S3_OPTIONS).size).toBe(0);
2264
+ expect(offeringsPlanColumns({ nope: true }, ["growth"], S3_OPTIONS).size).toBe(0);
2265
+ });
2266
+
2267
+ it("gives a price point its own price, and a bundle its bundle card's", () => {
2268
+ const set = s3((offerings) => {
2269
+ offerings.push(
2270
+ product("writer-4", "plan", [price("writer-4", "monthly", 40000, "usd"), price("writer-8", "monthly", 80000, "usd")], {
2271
+ name: "Writer",
2272
+ }),
2273
+ product("setup", "plan", [price("setup", "once", 50000, "usd")], { name: "Setup", requires: "retainer" }),
2274
+ product("retainer", "plan", [price("retainer", "monthly", 10000, "usd")], { name: "Retainer" }),
2275
+ );
2276
+ });
2277
+ const columns = offeringsPlanColumns(set, ["writer-4", "writer-8", "setup", "retainer"], S3_OPTIONS);
2278
+ expect(columns.get("writer-4")?.price.monthly).toBe("$400/mo");
2279
+ expect(columns.get("writer-8")?.price.monthly).toBe("$800/mo");
2280
+ expect(columns.get("writer-8")?.cta.href).toBe(`${OFFERINGS_CHECKOUT_PATH}/writer-8_monthly`);
2281
+ expect(columns.get("setup")?.cta.href).toBe(offeringsBundleHref("setup_once", "retainer_monthly"));
2282
+ expect(columns.has("retainer")).toBe(false);
2283
+ });
2284
+ });
2285
+
2286
+ // ─── #12241 — one pricing card for plans and add-ons ─────────────────────────
2287
+
2288
+ /** The spec's `ADDON_SET` (§ 5): `seo-audit` with a description and an eyebrow. */
2289
+ function addonSet(): WorkspaceShownSet {
2290
+ return shownSet((set) => {
2291
+ const seo = offering(set, "seo-audit");
2292
+ seo.description = "Audit desc";
2293
+ seo.eyebrow = "New";
2294
+ });
2295
+ }
2296
+
2297
+ describe("offeringsPricing — add-ons are cards (#12241 D3, AC-1)", () => {
2298
+ it("AC-1 mapper: one card per add-on, its description kept, and no `addons` key", () => {
2299
+ const addons = offeringsPricing(addonSet(), OPTIONS)!.addons!;
2300
+ expect(addons.plans.map((c) => c.key)).toEqual(["seo-audit", "audit-pack"]);
2301
+ expect(addons.plans.find((c) => c.key === "seo-audit")!.description).toBe("Audit desc");
2302
+ expect(addons).not.toHaveProperty("addons");
2303
+ expect(PricingSectionDataSchema.safeParse(addons).success).toBe(true);
2304
+ });
2305
+ });
2306
+
2307
+ describe("offeringsPricing — a level's detail from its Price (#12241 D6, AC-5)", () => {
2308
+ it("AC-5 mapper: a tier level takes its first monthly Price's detail; the card carries none", () => {
2309
+ const set = shownSet((s) => {
2310
+ s.offerings = [
2311
+ product("duo-a", "plan", [{ ...price("duo-a", "monthly", 1000, "usd"), detail: "Under $2M" }, price("duo-a", "yearly", 9600, "usd")], {
2312
+ tier: "Duo",
2313
+ level: "Early",
2314
+ ailkOrder: 1,
2315
+ }),
2316
+ product("duo-b", "plan", [price("duo-b", "monthly", 2000, "usd")], { tier: "Duo", level: "Growth", ailkOrder: 2 }),
2317
+ ];
2318
+ s.productIds = s.offerings.map((o) => o.productId);
2319
+ s.recommended = { plan: null, addon: null };
2320
+ });
2321
+ const duo = plansOf(tiers(set))[0]!;
2322
+ expect(duo.levels!.map((l) => l.label)).toEqual(["Early", "Growth"]);
2323
+ expect(duo.levels![0]!.detail).toBe("Under $2M");
2324
+ expect(duo.levels![1]).not.toHaveProperty("detail");
2325
+ expect(duo).not.toHaveProperty("detail");
2326
+ });
2327
+
2328
+ it("AC-5 mapper: a price point's own Price detail replaces its price phrase", () => {
2329
+ const set = writerSet(([w]) => [
2330
+ { ...w!, prices: w!.prices.map((p) => (p.plan === "writer-4" ? { ...p, detail: "Early" } : p)) },
2331
+ ]);
2332
+ const levels = plansOf(mapped(set))[0]!.levels!;
2333
+ expect(levels[0]!.detail).toBe("Early");
2334
+ expect(levels[1]!.detail).toBe(LABELS.monthly("$4,400"));
2335
+ });
2336
+ });
2337
+
2338
+ describe("offeringsPricing — Stripe's images ride the card (#12241 D8, AC-8)", () => {
2339
+ it("AC-8 mapper: a product's images become the card's images, each described by the card title", () => {
2340
+ const set = shownSet((s) => {
2341
+ const growth = offering(s, "growth");
2342
+ growth.shortName = "Grow";
2343
+ growth.images = ["https://files.example.com/a.png", "https://files.example.com/b.png"];
2344
+ });
2345
+ // A render-time field, outside the stored section type (as `offerPrices` is).
2346
+ expect((card(mapped(set), "growth") as { images?: unknown }).images).toEqual([
2347
+ { src: "https://files.example.com/a.png", alt: "Grow" },
2348
+ { src: "https://files.example.com/b.png", alt: "Grow" },
2349
+ ]);
2350
+ expect(card(mapped(), "growth")).not.toHaveProperty("images");
2351
+ });
2352
+ });
2353
+
2354
+ describe("offeringsPricing — checkout and the recommended add-on as before (#12241 AC-12)", () => {
2355
+ it("AC-12 mapper: each add-on card links its own checkout; the recommended one keeps its eyebrow and is not highlighted", () => {
2356
+ const result = mapped(shownSet());
2357
+ const seo = addonCard(result, "seo-audit");
2358
+ expect(seo.cta.href).toBe("/api/offerings/checkout/seo-audit_monthly");
2359
+ expect(seo.eyebrow).toBe(LABELS.recommended);
2360
+ expect(seo).not.toHaveProperty("highlighted");
2361
+ const pack = addonCard(result, "audit-pack");
2362
+ expect(pack.cta.href).toBe("/api/offerings/checkout/audit-pack_monthly");
2363
+ expect(pack.annualCtaHref).toBe("/api/offerings/checkout/audit-pack_yearly");
2364
+ });
2365
+
2366
+ it("AC-12 mapper: an add-on contact's card has no checkout link", () => {
2367
+ const commerce = addonCard(tiers(tierSet(), { collection: "growth-hub" }), "commerce");
2368
+ expect(JSON.stringify(commerce)).not.toContain(OFFERINGS_CHECKOUT_PATH);
2369
+ expect(commerce).not.toHaveProperty("annualCtaHref");
2370
+ });
2371
+ });
2372
+
2373
+ describe("offeringsPricing — the single card follows the toggle (#12241 D5, AC-14)", () => {
2374
+ it("AC-14 mapper: single-price-with-details over a both-periods plan carries billingToggle: true", () => {
2375
+ expect(
2376
+ offeringsPricing(shownSet(), { ...OPTIONS, plans: ["growth"], layout: "single-price-with-details" })!.plans,
2377
+ ).toHaveProperty("billingToggle", true);
2378
+ });
2379
+ });
2380
+
2381
+ // #12242 — the price on a Stripe-built card: amount and unit as two elements,
2382
+ // the unit joined by the site's one pattern, and the yearly-line and strike
2383
+ // options of a bound section.
2384
+ describe("price parts (#12242)", () => {
2385
+ const messages = jest.requireActual<{ pricingOfferings: Record<string, string> }>("../../messages/en.json");
2386
+ const m = messages.pricingOfferings;
2387
+ /** The shipped English words, built as `offeringsCopy` builds them. */
2388
+ const ENGLISH: OfferingsPricingLabels = {
2389
+ cta: m.cta!,
2390
+ recommended: m.recommended!,
2391
+ monthly: (amount) => m.monthly!.replace("{amount}", () => amount),
2392
+ annual: (amount) => m.annual!.replace("{amount}", () => amount),
2393
+ oneTime: (amount) => m.oneTime!.replace("{amount}", () => amount),
2394
+ withRequired: (plan, required) => m.withRequired!.replace("{plan}", () => plan).replace("{required}", () => required),
2395
+ depositNote: (deposit) => m.depositNote!.replace("{deposit}", () => deposit),
2396
+ billedYearly: (amount) => m.billedYearly!.replace("{amount}", () => amount),
2397
+ custom: m.custom!,
2398
+ perMonth: m.perMonth!,
2399
+ perYear: m.perYear!,
2400
+ unitWithLabel: (period, label) => m.unitWithLabel!.replace("{period}", () => period).replace("{label}", () => label),
2401
+ savings: (percent) => m.savings!.replace("{percent}", () => percent),
2402
+ regularPrice: (regular, current) =>
2403
+ m.regularPrice!.replace("{regular}", () => regular).replace("{current}", () => current),
2404
+ };
2405
+ const seat = (yearly = 20000, extra: Partial<OfferingsProduct> = {}, yearlyCurrency = "usd") =>
2406
+ product(
2407
+ "positionary",
2408
+ "plan",
2409
+ [price("positionary", "monthly", 2000, "usd"), price("positionary", "yearly", yearly, yearlyCurrency)],
2410
+ { unitLabel: "seat", ...extra },
2411
+ );
2412
+ const SEAT = seat();
2413
+ const SITE = product(
2414
+ "growth-hub",
2415
+ "plan",
2416
+ [price("growth-hub", "monthly", 2000, "usd"), price("growth-hub", "yearly", 20000, "usd")],
2417
+ { unitLabel: "site" },
2418
+ );
2419
+ const BARE = product(
2420
+ "bare",
2421
+ "plan",
2422
+ [price("bare", "monthly", 2000, "usd"), price("bare", "yearly", 20000, "usd")],
2423
+ );
2424
+ const YEARLY_ONLY = product("positionary", "plan", [price("positionary", "yearly", 20000, "usd")], { unitLabel: "seat" });
2425
+ const setOf = (...offerings: OfferingsProduct[]) =>
2426
+ shownSet((set) => {
2427
+ set.offerings = offerings;
2428
+ set.productIds = offerings.map((o) => o.productId);
2429
+ set.recommended = { plan: null, addon: null };
2430
+ });
2431
+ const cardsOf = (offerings: OfferingsProduct[], extra: Partial<Parameters<typeof offeringsPricing>[1]> = {}) =>
2432
+ plansOf(offeringsPricing(setOf(...offerings), { ...OPTIONS, ...extra })!);
2433
+ const one = (p: OfferingsProduct, extra: Partial<Parameters<typeof offeringsPricing>[1]> = {}) => cardsOf([p], extra)[0]!;
2434
+ type WithParts = { priceParts?: { monthly?: Record<string, string>; annual?: Record<string, string> } };
2435
+ const partsOf = (c: object) => (c as WithParts).priceParts;
2436
+
2437
+ it("AC-1 — a Stripe card keeps its price phrases and gains the amount and unit apart", () => {
2438
+ const c = one(SEAT, { labels: ENGLISH });
2439
+ expect(c.price).toEqual({ monthly: "$20/mo", annual: "$17/mo" });
2440
+ expect(partsOf(c)).toEqual({
2441
+ monthly: { amount: "$20", unit: "/mo/seat" },
2442
+ annual: { amount: "$17", unit: "/mo/seat" },
2443
+ });
2444
+ });
2445
+
2446
+ it("AC-2 — both sides of a monthly-and-yearly product read the per-month unit; a yearly-only one the yearly unit", () => {
2447
+ expect(partsOf(one(SEAT))).toEqual({
2448
+ monthly: { amount: "$20", unit: "U⟪PM⟪⟫seat" },
2449
+ annual: { amount: "$17", unit: "U⟪PM⟪⟫seat" },
2450
+ });
2451
+ expect(partsOf(one(YEARLY_ONLY))).toEqual({ annual: { amount: "$200", unit: "U⟪PY⟪⟫seat" } });
2452
+ });
2453
+
2454
+ it("AC-9 — one pattern joins every product's noun; no noun reads the period alone", () => {
2455
+ const units = (labels: OfferingsPricingLabels) =>
2456
+ cardsOf([SEAT, SITE, BARE], { labels }).map((c) => partsOf(c)!.monthly!.unit);
2457
+ expect(units(ENGLISH)).toEqual(["/mo/seat", "/mo/site", "/mo"]);
2458
+ expect(units({ ...ENGLISH, unitWithLabel: (p, l) => p + " per " + l })).toEqual(["/mo per seat", "/mo per site", "/mo"]);
2459
+ expect(JSON.stringify(messages).match(/"unitWithLabel"/g)).toHaveLength(1);
2460
+ });
2461
+
2462
+ it("AC-10 — the card's priceUnit is the noun as Stripe holds it, and the unit uses it unchanged", () => {
2463
+ const c = one(seat(20000, { unitLabel: "Seat" }), { labels: ENGLISH });
2464
+ expect(c.priceUnit).toBe("Seat");
2465
+ expect(partsOf(c)!.monthly!.unit).toBe("/mo/Seat");
2466
+ const dollar = one(seat(20000, { unitLabel: "$& seat" }), { labels: ENGLISH });
2467
+ expect(partsOf(dollar)!.monthly!.unit).toBe("/mo/$& seat");
2468
+ });
2469
+
2470
+ it("AC-4 — the yearly line: billed by default, a savings percentage, or none", () => {
2471
+ expect(one(SEAT).annualPriceNote).toBe("B⟪$200");
2472
+ expect(one(SEAT, { annualLine: "billed" }).annualPriceNote).toBe("B⟪$200");
2473
+ expect(one(SEAT, { annualLine: "savings" }).annualPriceNote).toBe("S⟪17");
2474
+ expect(one(SEAT, { annualLine: "none" })).not.toHaveProperty("annualPriceNote");
2475
+ expect(one(seat(24000), { annualLine: "savings" })).not.toHaveProperty("annualPriceNote");
2476
+ // 1 − 20280 ÷ 24000 = 15.5 % → 16; the rounded $17 per month would give 15.
2477
+ expect(one(seat(20280), { annualLine: "savings" }).annualPriceNote).toBe("S⟪16");
2478
+ expect(one(seat(25000), { annualLine: "savings" })).not.toHaveProperty("annualPriceNote");
2479
+ expect(one(seat(20000, {}, "eur"), { annualLine: "savings" })).not.toHaveProperty("annualPriceNote");
2480
+ for (const annualLine of [undefined, "billed", "savings", "none"] as const)
2481
+ expect(one(YEARLY_ONLY, { annualLine })).not.toHaveProperty("annualPriceNote");
2482
+ expect(one(SEAT, { labels: ENGLISH, annualLine: "savings" }).annualPriceNote).toBe("Save 17% billed annually");
2483
+ });
2484
+
2485
+ it("AC-5 — the strike: the standard monthly price on the yearly side only, with both prices named", () => {
2486
+ const parts = partsOf(one(SEAT, { labels: ENGLISH, strikeMonthly: true }))!;
2487
+ expect(parts.annual).toEqual({ amount: "$17", unit: "/mo/seat", was: "$20", wasLabel: "Regular price $20, now $17" });
2488
+ expect(parts.monthly).not.toHaveProperty("was");
2489
+ expect(partsOf(one(seat(24000), { strikeMonthly: true }))!.annual).not.toHaveProperty("was");
2490
+ expect(partsOf(one(seat(20000, {}, "eur"), { strikeMonthly: true }))!.annual).not.toHaveProperty("was");
2491
+ expect(partsOf(one(SEAT))!.annual).not.toHaveProperty("was");
2492
+ });
2493
+
2494
+ it("AC-1 — each level carries its own parts", () => {
2495
+ const tier = (plan: string, amount: number, order: number) =>
2496
+ product(plan, "plan", [price(plan, "monthly", amount, "usd")], { tier: "Team", level: plan, ailkOrder: order });
2497
+ const [c] = cardsOf([tier("small", 2000, 1), tier("large", 4000, 2)], { tiers: true });
2498
+ expect(c!.levels!.map((l) => partsOf(l)!.monthly!.amount)).toEqual(["$20", "$40"]);
2499
+ expect(partsOf(c!)!.monthly!.amount).toBe("$20");
2500
+ });
2501
+
2502
+ it("AC-7 — the phrases and notes are today's; bundles, one-time cards and the split blocks carry no parts", () => {
2503
+ // The fixture's cards keep every phrase and note they had (the suite's other cases, unedited).
2504
+ expect(card(mapped(), "growth")).toMatchObject({ priceUnit: "per seat", annualPriceNote: "B⟪$490" });
2505
+ const once = product("build", "plan", [price("build", "once", 300000, "usd")]);
2506
+ expect(one(once)).not.toHaveProperty("priceParts");
2507
+ const bundle = product("rebuild", "plan", [price("rebuild", "once", 250000, "usd")], { requires: "positionary" });
2508
+ const bundleCard = cardsOf([bundle, SEAT]).find((c) => c.key === "rebuild")!;
2509
+ expect(bundleCard).not.toHaveProperty("priceParts");
2510
+ const blocks = offeringsPricing(setOf(SEAT), { ...OPTIONS, layout: "features-and-plans" })!.plans!.plans;
2511
+ for (const block of blocks) expect(block).not.toHaveProperty("priceParts");
2512
+ expect(PricingSectionDataSchema.safeParse(offeringsPricing(setOf(SEAT), OPTIONS)!.plans).success).toBe(true);
2513
+ });
2514
+ });