create-ailk 0.46.1 → 0.46.3

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,7 @@ import {
24
25
  OFFERINGS_CHECKOUT_PATH,
25
26
  offeringsBundleHref,
26
27
  offeringsCheckoutHref,
28
+ collectionPlans,
27
29
  offeringsPricing,
28
30
  type OfferingsPricing,
29
31
  type OfferingsPricingLabels,
@@ -38,6 +40,7 @@ const LABELS: OfferingsPricingLabels = {
38
40
  withRequired: (plan, required) => "W⟪" + plan + "⟫" + required,
39
41
  depositNote: (deposit) => "D⟪" + deposit,
40
42
  billedYearly: (amount) => "B⟪" + amount,
43
+ custom: "C⟪",
41
44
  };
42
45
 
43
46
  const OPTIONS = { locale: "en-US", labels: LABELS };
@@ -280,7 +283,7 @@ describe("offeringsPricing — periods, the switch and the fields (AC-2)", () =>
280
283
  it("maps yearly to annual and lands unit, note and terms note in their fields", () => {
281
284
  const growth = card(mapped(), "growth");
282
285
  // #12139 D1: annual mode shows the yearly Price per month.
283
- expect(growth.price).toEqual({ monthly: "M⟪$49", annual: "M⟪$40.83" });
286
+ expect(growth.price).toEqual({ monthly: "M⟪$49", annual: "M⟪$41" });
284
287
  expect(growth.priceUnit).toBe("per seat");
285
288
  expect(growth.priceSubhead).toBe("Billed per active seat");
286
289
  expect(growth.priceFootnote).toBe("Cancel any time from your account");
@@ -966,10 +969,11 @@ describe("offeringsPricing — the annual price per month (#12139 D1, AC-2)", ()
966
969
  expect(annual.annualCtaHref).toBe("/api/offerings/checkout/annual-plan_yearly");
967
970
  });
968
971
 
969
- it("rounds the per-month amount to the nearest minor unit", () => {
972
+ // #12193 D8 — whole currency units, was the nearest minor unit.
973
+ it("rounds the per-month amount to whole currency units", () => {
970
974
  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");
975
+ expect(card(result, "odd-plan").price.annual).toBe("M⟪$41");
976
+ expect(card(result, "round-up-plan").price.annual).toBe("M⟪$50");
973
977
  expect(card(result, "whole-plan").price.annual).toBe("M⟪$10");
974
978
  expect(card(result, "yen-plan").price.annual).toBe("M⟪¥833");
975
979
  expect(card(result, "yen-plan").annualPriceNote).toBe("B⟪¥10,000");
@@ -1130,6 +1134,7 @@ describe("offeringsPricing — features-and-plans splits one product into two bl
1130
1134
  highlighted: true,
1131
1135
  highlightStyle: "pill",
1132
1136
  highlightLabel: "REC⟪",
1137
+ offerPrices: [{ amount: "49", currency: "USD", period: "month" }],
1133
1138
  },
1134
1139
  {
1135
1140
  key: "growth_yearly",
@@ -1140,6 +1145,7 @@ describe("offeringsPricing — features-and-plans splits one product into two bl
1140
1145
  priceUnit: "per seat",
1141
1146
  priceSubhead: "Billed per active seat",
1142
1147
  priceFootnote: "Cancel any time from your account",
1148
+ offerPrices: [{ amount: "490", currency: "USD", period: "year" }],
1143
1149
  },
1144
1150
  ],
1145
1151
  });
@@ -1198,3 +1204,815 @@ describe("offeringsPricing — no layout names a vendor; every link is ours (#12
1198
1204
  for (const href of links) expect(href.startsWith(OFFERINGS_CHECKOUT_PATH)).toBe(true);
1199
1205
  });
1200
1206
  });
1207
+
1208
+ // ─── #12174 — Offerings plans grouped into level cards (D6, AC-5) ───────────
1209
+
1210
+ /** Three plan products of one tier, pushed onto the fixture (`productIds` in step). */
1211
+ function levelSet(
1212
+ edit: (offerings: OfferingsProduct[]) => OfferingsProduct[] = (o) => o,
1213
+ ): WorkspaceShownSet {
1214
+ return shownSet((set) => {
1215
+ const levels = edit([
1216
+ product(
1217
+ "ind-msg",
1218
+ "plan",
1219
+ [price("ind-msg", "monthly", 24900, "usd"), price("ind-msg", "yearly", 256800, "usd")],
1220
+ {
1221
+ name: "Growth Platform Individual Messaging",
1222
+ marketingFeatures: ["One Messaging seat"],
1223
+ note: "Setup included",
1224
+ },
1225
+ ),
1226
+ product(
1227
+ "ind-pb",
1228
+ "plan",
1229
+ [price("ind-pb", "monthly", 29900, "usd"), price("ind-pb", "yearly", 306800, "usd")],
1230
+ { name: "Growth Platform Individual Playbooks", marketingFeatures: ["One Playbooks seat"] },
1231
+ ),
1232
+ product("ind-suite", "plan", [price("ind-suite", "monthly", 38900, "usd")], {
1233
+ name: "Growth Platform Individual Brand Suite",
1234
+ marketingFeatures: ["One Brand Suite seat"],
1235
+ }),
1236
+ ]);
1237
+ set.offerings.push(...levels);
1238
+ set.productIds = set.offerings.map((o) => o.productId);
1239
+ });
1240
+ }
1241
+
1242
+ const INDIVIDUAL = {
1243
+ key: "individual",
1244
+ name: "Individual",
1245
+ levels: [
1246
+ { label: "Messaging", plan: "ind-msg" },
1247
+ { label: "Playbooks", plan: "ind-pb" },
1248
+ { label: "Suite", plan: "ind-suite" },
1249
+ ],
1250
+ };
1251
+ const LEVEL_PLANS = ["ind-msg", "ind-pb", "ind-suite"];
1252
+
1253
+ function grouped(set: WorkspaceShownSet, group = INDIVIDUAL) {
1254
+ return offeringsPricing(set, { ...OPTIONS, plans: LEVEL_PLANS, levelGroups: [group] });
1255
+ }
1256
+
1257
+ describe("offeringsPricing — levelGroups (#12174 D6, AC-5)", () => {
1258
+ it("groups the plans into one card titled and labelled by the page", () => {
1259
+ const result = grouped(levelSet())!;
1260
+ const cards = plansOf(result);
1261
+ expect(cards).toHaveLength(1);
1262
+ const card = cards[0]!;
1263
+ expect(card.key).toBe("individual");
1264
+ expect(card.name).toBe("Individual");
1265
+ const levels = card.levels!;
1266
+ expect(levels.map((l) => l.label)).toEqual(["Messaging", "Playbooks", "Suite"]);
1267
+ expect(levels.map((l) => l.key)).toEqual(LEVEL_PLANS);
1268
+ expect(levels[0]!.price).toEqual({ monthly: "M⟪$249", annual: "M⟪$214" });
1269
+ expect(levels[0]!.annualPriceNote).toBe("B⟪$2,568");
1270
+ expect(levels[0]!.priceSubhead).toBe("Setup included");
1271
+ expect(levels[1]).not.toHaveProperty("priceSubhead");
1272
+ expect(levels[2]!.price).toEqual({ monthly: "M⟪$389" });
1273
+ expect(levels[2]).not.toHaveProperty("annualCtaHref");
1274
+ expect(card.price).toEqual(levels[0]!.price);
1275
+ expect(card.features).toEqual(levels[0]!.features);
1276
+ expect(card.cta).toEqual(levels[0]!.cta);
1277
+ const names = levelSet().offerings.map((o) => o.name);
1278
+ const strings = JSON.stringify(card).match(/"[^"]*"/g)!.map((s) => s.slice(1, -1));
1279
+ for (const name of names) expect(strings).not.toContain(name);
1280
+ expect(result.plans!.billingToggle).toBe(true);
1281
+ });
1282
+
1283
+ it("keeps the authored level order", () => {
1284
+ const group = { ...INDIVIDUAL, levels: [INDIVIDUAL.levels[2]!, INDIVIDUAL.levels[0]!] };
1285
+ expect(plansOf(grouped(levelSet(), group)!)[0]!.levels!.map((l) => l.label)).toEqual(["Suite", "Messaging"]);
1286
+ });
1287
+
1288
+ it("drops a level whose plan is not shown, and the card when none is", () => {
1289
+ const two = grouped(levelSet((o) => o.filter((p) => p.plan !== "ind-pb")))!;
1290
+ expect(plansOf(two)[0]!.levels!.map((l) => l.label)).toEqual(["Messaging", "Suite"]);
1291
+ const none = grouped(levelSet(() => []))!;
1292
+ expect(none.plans).toBeNull();
1293
+ });
1294
+
1295
+ it("highlights the card that sells the first recommended plan", () => {
1296
+ const card = plansOf(
1297
+ grouped(levelSet((o) => o.map((p) => (p.plan === "ind-suite" ? { ...p, recommended: true } : p))))!,
1298
+ )[0]!;
1299
+ expect(card.highlighted).toBe(true);
1300
+ expect(card.highlightStyle).toBe("pill");
1301
+ expect(card.highlightLabel).toBe("REC⟪");
1302
+ });
1303
+
1304
+ it("turns the toggle on for a level priced both ways when the first is not", () => {
1305
+ const set = levelSet((o) =>
1306
+ o.map((p) => (p.plan === "ind-msg" ? { ...p, prices: p.prices.filter((x) => x.period === "monthly") } : p)),
1307
+ );
1308
+ expect(grouped(set)!.plans!.billingToggle).toBe(true);
1309
+ });
1310
+
1311
+ it("changes nothing for a call that passes no levelGroups", () => {
1312
+ expect(offeringsPricing(levelSet(), OPTIONS)).toEqual(
1313
+ offeringsPricing(levelSet(), { ...OPTIONS, levelGroups: undefined }),
1314
+ );
1315
+ expect(plansOf(mapped(levelSet())).map((c) => c.key)).toEqual([
1316
+ "starter",
1317
+ "growth",
1318
+ "basic",
1319
+ "ind-msg",
1320
+ "ind-pb",
1321
+ "ind-suite",
1322
+ ]);
1323
+ });
1324
+ });
1325
+
1326
+ // ─── #12193 — cards built from Stripe ───────────────────────────────────────
1327
+
1328
+ /**
1329
+ * The spec's TIER_SET (§ 5): the three Individual plans as one tier of a
1330
+ * collection, a Team tier of one, an Essentials plan of another collection, an
1331
+ * SEO add-on, and two contacts — the Enterprise plan and the Commerce add-on.
1332
+ */
1333
+ function tierSet(
1334
+ edit: (offerings: OfferingsProduct[], contacts: OfferingsContactProduct[]) => void = () => {},
1335
+ ): WorkspaceShownSet {
1336
+ return shownSet((set) => {
1337
+ const meta = [
1338
+ { level: "Messaging", ailkOrder: 10, description: "Msg desc" },
1339
+ { level: "Playbooks", ailkOrder: 20, description: "PB desc" },
1340
+ { level: "Suite", ailkOrder: 30, description: null },
1341
+ ];
1342
+ const individual = levelSet().offerings.slice(-3).map((o, i) => ({
1343
+ ...o,
1344
+ collection: "growth-platform",
1345
+ tier: "Individual",
1346
+ ...meta[i]!,
1347
+ }));
1348
+ const offerings: OfferingsProduct[] = [
1349
+ ...individual,
1350
+ product("team-msg", "plan", [price("team-msg", "monthly", 44900, "usd"), price("team-msg", "yearly", 471600, "usd")], {
1351
+ collection: "growth-platform",
1352
+ tier: "Team",
1353
+ level: "Messaging",
1354
+ ailkOrder: 40,
1355
+ description: "Team desc",
1356
+ }),
1357
+ product("essentials", "plan", [price("essentials", "monthly", 9900, "usd")], {
1358
+ collection: "content-factory",
1359
+ shortName: "Essentials",
1360
+ name: "Content Factory - Essentials",
1361
+ }),
1362
+ product("seo", "addon", [price("seo", "once", 19900, "usd")], { collection: "growth-hub", shortName: "SEO" }),
1363
+ ];
1364
+ const contacts: OfferingsContactProduct[] = [
1365
+ {
1366
+ productId: "prod_enterprise",
1367
+ plan: "enterprise",
1368
+ ailkGroup: "plan",
1369
+ name: "Growth Platform Enterprise",
1370
+ description: null,
1371
+ marketingFeatures: ["Everything in Team"],
1372
+ ailkOrder: 50,
1373
+ url: "https://example.com/meet?x=1",
1374
+ ctaLabel: "Book a call",
1375
+ tier: "Enterprise",
1376
+ collection: "growth-platform",
1377
+ },
1378
+ {
1379
+ productId: "prod_commerce",
1380
+ plan: "commerce",
1381
+ ailkGroup: "addon",
1382
+ name: "Growth Hub Commerce",
1383
+ description: null,
1384
+ marketingFeatures: [],
1385
+ ailkOrder: null,
1386
+ url: "https://example.com/contact",
1387
+ ctaLabel: "Talk to us",
1388
+ priceText: "From 179 USD a month",
1389
+ shortName: "Commerce",
1390
+ collection: "growth-hub",
1391
+ },
1392
+ ];
1393
+ edit(offerings, contacts);
1394
+ set.offerings = offerings;
1395
+ set.productIds = offerings.map((o) => o.productId);
1396
+ set.recommended = { plan: null, addon: null };
1397
+ set.contacts = contacts;
1398
+ });
1399
+ }
1400
+
1401
+ const SITE = { siteOrigin: "https://example.com" };
1402
+ const tiers = (set: WorkspaceShownSet, extra: Record<string, unknown> = {}) =>
1403
+ offeringsPricing(set, { ...OPTIONS, ...SITE, tiers: true, ...extra })!;
1404
+
1405
+ describe("offeringsPricing — tier cards (#12193 D5, AC-2)", () => {
1406
+ it("groups a tier's plans into one level card titled by the tier, labelled and ordered from Stripe", () => {
1407
+ const cards = plansOf(tiers(tierSet(), { collection: "growth-platform" }));
1408
+ expect(cards.map((c) => c.key)).toEqual(["ind-msg", "team-msg", "enterprise"]);
1409
+ const individual = cards[0]!;
1410
+ expect(individual.name).toBe("Individual");
1411
+ expect(individual.levels!.map((l) => l.label)).toEqual(["Messaging", "Playbooks", "Suite"]);
1412
+ expect(individual.levels!.map((l) => l.key)).toEqual(["ind-msg", "ind-pb", "ind-suite"]);
1413
+ expect(individual.levels!.map((l) => l.description)).toEqual(["Msg desc", "PB desc", undefined]);
1414
+ expect(individual.levels![2]).not.toHaveProperty("description");
1415
+ expect(individual.description).toBe("Msg desc");
1416
+ const team = cards[1]!;
1417
+ expect(team.name).toBe("Team");
1418
+ expect(team).not.toHaveProperty("levels");
1419
+ });
1420
+
1421
+ it("orders the levels by ailk_order", () => {
1422
+ const set = tierSet((o) => {
1423
+ o.find((p) => p.plan === "ind-pb")!.ailkOrder = 5;
1424
+ });
1425
+ const individual = plansOf(tiers(set, { collection: "growth-platform" }))[0]!;
1426
+ expect(individual.levels!.map((l) => l.label)).toEqual(["Playbooks", "Messaging", "Suite"]);
1427
+ });
1428
+
1429
+ it("falls back to the short name or name for a repeated label, so the labels stay distinct", () => {
1430
+ const set = tierSet((o) => {
1431
+ o.find((p) => p.plan === "ind-pb")!.level = "Messaging";
1432
+ });
1433
+ const labels = plansOf(tiers(set, { collection: "growth-platform" }))[0]!.levels!.map((l) => l.label);
1434
+ expect(new Set(labels).size).toBe(labels.length);
1435
+ expect(labels[1]).toBe("Growth Platform Individual Playbooks");
1436
+ });
1437
+
1438
+ it("keeps at most four levels", () => {
1439
+ const set = tierSet((o) => {
1440
+ for (const n of [1, 2]) {
1441
+ o.push(
1442
+ product(`ind-x${n}`, "plan", [price(`ind-x${n}`, "monthly", 50000, "usd")], {
1443
+ collection: "growth-platform",
1444
+ tier: "Individual",
1445
+ level: `X${n}`,
1446
+ ailkOrder: 30 + n,
1447
+ }),
1448
+ );
1449
+ }
1450
+ });
1451
+ expect(plansOf(tiers(set, { collection: "growth-platform" }))[0]!.levels).toHaveLength(4);
1452
+ });
1453
+ });
1454
+
1455
+ describe("offeringsPricing — ailk_name titles a card (#12193 D5 rule 3, D6, AC-3)", () => {
1456
+ it("titles a plan with no tier by its short name, outside tier mode too; the snapshot keeps the Stripe name", () => {
1457
+ const set = tierSet();
1458
+ expect(card(offeringsPricing(set, { ...OPTIONS, plans: ["essentials"] })!, "essentials").name).toBe("Essentials");
1459
+ expect(offering(set, "essentials").name).toBe("Content Factory - Essentials");
1460
+ });
1461
+
1462
+ it("titles an add-on tile by its short name", () => {
1463
+ expect(tile(offeringsPricing(tierSet(), OPTIONS)!, "seo").name).toBe("SEO");
1464
+ });
1465
+ });
1466
+
1467
+ describe("offeringsPricing — a collection (#12193 D5 rule 1, AC-4)", () => {
1468
+ it("shows every shown plan of the collection, compared lowercased, and no other", () => {
1469
+ const set = tierSet((o) => {
1470
+ for (const p of o) if (p.collection === "growth-platform") p.collection = "Growth-Platform";
1471
+ });
1472
+ const keys = plansOf(tiers(set, { collection: "growth-platform" })).map((c) => c.key);
1473
+ expect(keys).toEqual(["ind-msg", "team-msg", "enterprise"]);
1474
+ expect(keys).not.toContain("essentials");
1475
+ });
1476
+
1477
+ it("collectionPlans names the collection's plan slugs, contacts included", () => {
1478
+ expect(collectionPlans(tierSet(), "growth-platform")).toEqual(["ind-msg", "ind-pb", "ind-suite", "team-msg", "enterprise"]);
1479
+ expect(collectionPlans(tierSet(), "nothing")).toEqual([]);
1480
+ });
1481
+ });
1482
+
1483
+ describe("offeringsPricing — the contact card (#12193 D5 rule 7, AC-5, AC-6)", () => {
1484
+ const enterprise = (set = tierSet(), extra: Record<string, unknown> = {}) =>
1485
+ card(tiers(set, { collection: "growth-platform", ...extra }), "enterprise");
1486
+
1487
+ it("is a card in the same grid: tier title, translated Custom, the ailk_cta label and a same-site internal link", () => {
1488
+ expect(enterprise()).toEqual({
1489
+ key: "enterprise",
1490
+ name: "Enterprise",
1491
+ price: { custom: "C⟪" },
1492
+ cta: { label: "Book a call", href: "/meet?x=1" },
1493
+ features: ["Everything in Team"],
1494
+ offerPrices: [],
1495
+ });
1496
+ });
1497
+
1498
+ it("is an external link on another origin", () => {
1499
+ expect(enterprise(tierSet(), { siteOrigin: "https://other.test" }).cta).toEqual({
1500
+ label: "Book a call",
1501
+ href: "https://example.com/meet?x=1",
1502
+ external: true,
1503
+ });
1504
+ });
1505
+
1506
+ it("treats a same-origin path starting with // as external", () => {
1507
+ const set = tierSet((_o, c) => {
1508
+ c[0]!.url = "https://example.com//evil.test/x";
1509
+ });
1510
+ expect(enterprise(set).cta).toEqual({ label: "Book a call", href: "https://example.com//evil.test/x", external: true });
1511
+ });
1512
+
1513
+ it.each([
1514
+ ["a same-origin /api/ path", "https://example.com/API/offerings/checkout/a_monthly"],
1515
+ ["a percent-encoded /api/ path", "https://example.com/%61pi/offerings/checkout/a_monthly"],
1516
+ ["a path that does not percent-decode", "https://example.com/%zz"],
1517
+ ["the bare same-origin /api path", "https://example.com/api?x=1"],
1518
+ ])("gives no card for %s, and never throws", (_label, url) => {
1519
+ const set = tierSet((_o, c) => {
1520
+ c[0]!.url = url;
1521
+ });
1522
+ expect(plansOf(tiers(set, { collection: "growth-platform" })).map((c) => c.key)).not.toContain("enterprise");
1523
+ });
1524
+
1525
+ it("shows ailk_price_text in the price slot and publishes no priced Offer (AC-6)", () => {
1526
+ const set = tierSet((_o, c) => {
1527
+ c[0]!.priceText = "From 179 USD a month";
1528
+ });
1529
+ const contact = enterprise(set);
1530
+ expect(contact.price).toEqual({ custom: "From 179 USD a month" });
1531
+ expect((contact as { offerPrices?: unknown }).offerPrices).toEqual([]);
1532
+ });
1533
+
1534
+ it("is never highlighted, and appears in no section that names its plans or maps the page's plans", () => {
1535
+ expect(enterprise()).not.toHaveProperty("highlighted");
1536
+ const keys = (result: OfferingsPricing | null) => (result?.plans?.plans ?? []).map((c) => c.key);
1537
+ expect(keys(offeringsPricing(tierSet(), OPTIONS))).not.toContain("enterprise");
1538
+ expect(keys(offeringsPricing(tierSet(), { ...OPTIONS, ...SITE, tiers: true }))).not.toContain("enterprise");
1539
+ });
1540
+ });
1541
+
1542
+ describe("offeringsPricing — the add-on contact tile (#12193 AC-7)", () => {
1543
+ it("an add-ons collection shows the add-on and the contact tile with its display price, label and link", () => {
1544
+ const addons = addonsOf(tiers(tierSet(), { collection: "growth-hub" }));
1545
+ expect(addons.map((t) => t.key)).toEqual(["seo", "commerce"]);
1546
+ expect(addons[0]!.name).toBe("SEO");
1547
+ expect(addons[1]).toEqual({
1548
+ key: "commerce",
1549
+ name: "Commerce",
1550
+ price: "From 179 USD a month",
1551
+ features: [],
1552
+ cta: { label: "Talk to us", href: "/contact" },
1553
+ });
1554
+ });
1555
+ });
1556
+
1557
+ describe("offeringsPricing — whole dollars per month (#12193 D8, AC-12)", () => {
1558
+ const level = (set: WorkspaceShownSet, plan: string) =>
1559
+ plansOf(offeringsPricing(set, { ...OPTIONS, plans: LEVEL_PLANS, levelGroups: [INDIVIDUAL] })!)[0]!.levels!.find(
1560
+ (l) => l.key === plan,
1561
+ )!;
1562
+
1563
+ it("rounds a per-month price derived from a yearly price to whole dollars, keeping the exact yearly total", () => {
1564
+ expect(level(levelSet(), "ind-pb").price.annual).toBe("M⟪$256");
1565
+ expect(level(levelSet(), "ind-pb").annualPriceNote).toBe("B⟪$3,068");
1566
+ expect(level(levelSet(), "ind-msg").price.annual).toBe("M⟪$214");
1567
+ const cents = levelSet((o) =>
1568
+ o.map((p) =>
1569
+ p.plan === "ind-pb"
1570
+ ? { ...p, prices: p.prices.map((x) => (x.period === "yearly" ? { ...x, amount: 306850 } : x)) }
1571
+ : p,
1572
+ ),
1573
+ );
1574
+ expect(level(cents, "ind-pb").price.annual).toBe("M⟪$256");
1575
+ expect(level(cents, "ind-pb").annualPriceNote).toBe("B⟪$3,068.50");
1576
+ });
1577
+
1578
+ it("leaves a zero-decimal currency as it is", () => {
1579
+ const set = shownSet((s) => {
1580
+ s.offerings = [product("yen", "plan", [price("yen", "monthly", 1000, "jpy"), price("yen", "yearly", 10000, "jpy")])];
1581
+ s.productIds = ["prod_yen"];
1582
+ s.recommended = { plan: null, addon: null };
1583
+ });
1584
+ expect(card(offeringsPricing(set, OPTIONS)!, "yen").price.annual).toBe("M⟪¥833");
1585
+ });
1586
+ });
1587
+
1588
+ describe("offeringsPricing — offerPrices for the JSON-LD (#12193 D9, AC-13)", () => {
1589
+ it("carries each shown Price at full precision in major units, on a card and its level", () => {
1590
+ const result = offeringsPricing(levelSet(), { ...OPTIONS, plans: LEVEL_PLANS, levelGroups: [INDIVIDUAL] })!;
1591
+ const levels = plansOf(result)[0]!.levels! as Array<{ offerPrices?: unknown }>;
1592
+ expect(levels[0]!.offerPrices).toEqual([
1593
+ { amount: "249", currency: "USD", period: "month" },
1594
+ { amount: "2568", currency: "USD", period: "year" },
1595
+ ]);
1596
+ const plain = card(offeringsPricing(levelSet(), OPTIONS)!, "ind-pb") as { offerPrices?: unknown };
1597
+ expect(plain.offerPrices).toEqual([
1598
+ { amount: "299", currency: "USD", period: "month" },
1599
+ { amount: "3068", currency: "USD", period: "year" },
1600
+ ]);
1601
+ });
1602
+ });
1603
+
1604
+ describe("offeringsPricing — 0.76.0 sections render as before (#12193 AC-17)", () => {
1605
+ it("an offeringGroups card keeps its page title when its products carry a tier, and levels carry no description", () => {
1606
+ const set = levelSet((o) => o.map((p) => ({ ...p, tier: "Other", description: "Stripe desc" })));
1607
+ const c = plansOf(offeringsPricing(set, { ...OPTIONS, plans: LEVEL_PLANS, levelGroups: [INDIVIDUAL] })!)[0]!;
1608
+ expect(c.name).toBe("Individual");
1609
+ for (const l of c.levels!) expect(l).not.toHaveProperty("description");
1610
+ expect(c).not.toHaveProperty("description");
1611
+ });
1612
+
1613
+ it("a section naming its plans keeps one card per plan though they carry a tier", () => {
1614
+ const cards = plansOf(offeringsPricing(tierSet(), { ...OPTIONS, plans: ["ind-msg", "ind-pb"] })!);
1615
+ expect(cards.map((c) => c.key)).toEqual(["ind-msg", "ind-pb"]);
1616
+ for (const c of cards) expect(c).not.toHaveProperty("levels");
1617
+ });
1618
+
1619
+ it("no unbound mapping shows a contact", () => {
1620
+ const result = offeringsPricing(tierSet(), OPTIONS)!;
1621
+ expect(plansOf(result).map((c) => c.key)).not.toContain("enterprise");
1622
+ expect(addonsOf(result).map((t) => t.key)).not.toContain("commerce");
1623
+ });
1624
+ });
1625
+
1626
+ // ─── #12209 — helper text, twenty levels and separate tier cards ─────────────
1627
+
1628
+ describe("offeringsPricing — a plan's helper text becomes its level's (#12209 D5, AC-5)", () => {
1629
+ const helped = (set: WorkspaceShownSet, helpers: Record<string, string>) => {
1630
+ for (const o of set.offerings) if (helpers[o.plan] !== undefined) o.switchHelper = helpers[o.plan];
1631
+ return set;
1632
+ };
1633
+
1634
+ it("a tier's levels take their products' helpers; the card carries none", () => {
1635
+ const set = helped(tierSet(), { "ind-msg": "per brand", "ind-pb": "per team" });
1636
+ const individual = plansOf(tiers(set, { collection: "growth-platform" }))[0]!;
1637
+ expect(individual.levels!.map((l) => l.helper)).toEqual(["per brand", "per team", undefined]);
1638
+ expect(individual.levels![2]).not.toHaveProperty("helper");
1639
+ expect(individual).not.toHaveProperty("helper");
1640
+ expect(individual).not.toHaveProperty("levelHelper");
1641
+ });
1642
+
1643
+ it("an offeringGroups card's levels take their products' helpers; the card carries none", () => {
1644
+ const set = helped(levelSet(), { "ind-msg": "per brand" });
1645
+ const card = plansOf(grouped(set)!)[0]!;
1646
+ expect(card.levels![0]!.helper).toBe("per brand");
1647
+ expect(card.levels![1]).not.toHaveProperty("helper");
1648
+ expect(card).not.toHaveProperty("helper");
1649
+ expect(card).not.toHaveProperty("levelHelper");
1650
+ });
1651
+
1652
+ it("a lone plan's card carries none (the Admin preview's planCard is unchanged)", () => {
1653
+ const set = helped(levelSet(), { "ind-msg": "per brand" });
1654
+ const lone = card(offeringsPricing(set, { ...OPTIONS, plans: ["ind-msg"] })!, "ind-msg");
1655
+ expect(lone).not.toHaveProperty("helper");
1656
+ expect(lone).not.toHaveProperty("levelHelper");
1657
+ expect(JSON.stringify(lone)).not.toContain("per brand");
1658
+ });
1659
+ });
1660
+
1661
+ describe("offeringsPricing — an offeringGroups card's control (#12209 D2, AC-1)", () => {
1662
+ it("copies the group's levelSwitchControl onto its card, and sets none when the group sets none", () => {
1663
+ const withControl = plansOf(
1664
+ offeringsPricing(levelSet(), {
1665
+ ...OPTIONS,
1666
+ plans: LEVEL_PLANS,
1667
+ levelGroups: [{ ...INDIVIDUAL, levelSwitchControl: "select" as const }],
1668
+ })!,
1669
+ )[0]!;
1670
+ expect(withControl.levelSwitchControl).toBe("select");
1671
+ expect(plansOf(grouped(levelSet())!)[0]!).not.toHaveProperty("levelSwitchControl");
1672
+ });
1673
+ });
1674
+
1675
+ describe("offeringsPricing — the level limit (#12209 D8, AC-8)", () => {
1676
+ const twentyTwo = () =>
1677
+ tierSet((o) => {
1678
+ for (let n = 1; n <= 22; n++) {
1679
+ o.push(
1680
+ product(`ind-n${n}`, "plan", [price(`ind-n${n}`, "monthly", 1000 * n, "usd")], {
1681
+ collection: "big",
1682
+ tier: "Big",
1683
+ level: `N${n}`,
1684
+ ailkOrder: 100 + n,
1685
+ }),
1686
+ );
1687
+ }
1688
+ });
1689
+
1690
+ it("keeps twenty levels, in snapshot order, with levelLimit 20; four without it", () => {
1691
+ const twenty = plansOf(tiers(twentyTwo(), { collection: "big", levelLimit: 20 }))[0]!;
1692
+ expect(twenty.levels!.map((l) => l.label)).toEqual(Array.from({ length: 20 }, (_, i) => `N${i + 1}`));
1693
+ expect(plansOf(tiers(twentyTwo(), { collection: "big" }))[0]!.levels).toHaveLength(4);
1694
+ });
1695
+ });
1696
+
1697
+ describe("offeringsPricing — separate tier cards (#12209 D11, AC-9)", () => {
1698
+ it("groupTiers: false makes every plan its own card, titled by its own name, the collection and order kept", () => {
1699
+ const cards = plansOf(tiers(tierSet(), { collection: "growth-platform", groupTiers: false }));
1700
+ expect(cards.map((c) => c.key)).toEqual(["ind-msg", "ind-pb", "ind-suite", "team-msg", "enterprise"]);
1701
+ for (const c of cards) expect(c).not.toHaveProperty("levels");
1702
+ const first = offering(tierSet(), "ind-msg");
1703
+ expect(cards[0]!.name).toBe(first.shortName ?? first.name);
1704
+ expect(cards[0]!.name).not.toBe("Individual");
1705
+ });
1706
+
1707
+ it("without groupTiers, the tier is one card as before", () => {
1708
+ expect(tiers(tierSet(), { collection: "growth-platform", groupTiers: undefined })).toEqual(
1709
+ tiers(tierSet(), { collection: "growth-platform" }),
1710
+ );
1711
+ });
1712
+ });
1713
+
1714
+ describe("offeringsPricing — the yearly line stays the mapper's (#12209 D7, AC-7)", () => {
1715
+ it("sets billed-yearly beside both Prices and never on a monthly-only plan", () => {
1716
+ const set = shownSet((s) => {
1717
+ s.offerings = [
1718
+ product("both", "plan", [price("both", "monthly", 24900, "usd"), price("both", "yearly", 256800, "usd")]),
1719
+ product("month", "plan", [price("month", "monthly", 24900, "usd")]),
1720
+ ];
1721
+ s.productIds = s.offerings.map((o) => o.productId);
1722
+ s.recommended = { plan: null, addon: null };
1723
+ });
1724
+ const result = offeringsPricing(set, OPTIONS)!;
1725
+ expect(card(result, "both").annualPriceNote).toBe("B⟪$2,568");
1726
+ expect(card(result, "month")).not.toHaveProperty("annualPriceNote");
1727
+ });
1728
+ });
1729
+
1730
+ // ─── #12210 — several prices on one Stripe product ───────────────────────────
1731
+
1732
+ /** A monthly Price of one price point, with its normalized nickname. */
1733
+ function pointPrice(plan: string, amount: number, label?: string): OfferingsPrice {
1734
+ const p = price(plan, "monthly", amount, "usd");
1735
+ return label === undefined ? p : { ...p, label };
1736
+ }
1737
+
1738
+ /** Hire a Writer (spec § 5 `WRITER_SET`): one plan product, three monthly points. */
1739
+ function writer(extra: Partial<OfferingsProduct> = {}): OfferingsProduct {
1740
+ return product(
1741
+ "writer-4",
1742
+ "plan",
1743
+ [
1744
+ pointPrice("writer-4", 220000, "4 pieces/mo"),
1745
+ pointPrice("writer-8", 440000, "8 pieces/mo"),
1746
+ pointPrice("writer-12", 660000, "12 pieces/mo"),
1747
+ ],
1748
+ {
1749
+ productId: "prod_writer",
1750
+ name: "Hire a Writer",
1751
+ description: "Writing, done",
1752
+ marketingFeatures: ["Edited"],
1753
+ ...extra,
1754
+ },
1755
+ );
1756
+ }
1757
+
1758
+ function writerSet(edit: (offerings: OfferingsProduct[]) => OfferingsProduct[] | void = () => {}): WorkspaceShownSet {
1759
+ return shownSet((s) => {
1760
+ s.offerings = [writer()];
1761
+ s.offerings = edit(s.offerings) ?? s.offerings;
1762
+ s.productIds = s.offerings.map((o) => o.productId);
1763
+ s.recommended = { plan: null, addon: null };
1764
+ });
1765
+ }
1766
+
1767
+ /** A plan product with `n` monthly points `p-1` … `p-n`, labelled `P1` … `Pn`. */
1768
+ function pointsProduct(n: number, extra: Partial<OfferingsProduct> = {}): OfferingsProduct {
1769
+ return product(
1770
+ "p-1",
1771
+ "plan",
1772
+ Array.from({ length: n }, (_, i) => pointPrice(`p-${i + 1}`, 1000 * (i + 1), `P${i + 1}`)),
1773
+ { productId: "prod_points", name: "Points", ...extra },
1774
+ );
1775
+ }
1776
+
1777
+ describe("offeringsPricing — a product's price points are one card's levels (#12210 D6, AC-1)", () => {
1778
+ it("one card keyed by the first point, titled by the product, one level per point labelled by its nickname", () => {
1779
+ const cards = plansOf(mapped(writerSet()));
1780
+ expect(cards).toHaveLength(1);
1781
+ const c = cards[0]!;
1782
+ expect(c.key).toBe("writer-4");
1783
+ expect(c.name).toBe("Hire a Writer");
1784
+ expect(c.levels!.map((l) => l.key)).toEqual(["writer-4", "writer-8", "writer-12"]);
1785
+ expect(c.levels!.map((l) => l.label)).toEqual(["4 pieces/mo", "8 pieces/mo", "12 pieces/mo"]);
1786
+ });
1787
+
1788
+ it("each level's secondary label is its amount, the select item's detail", () => {
1789
+ const c = plansOf(mapped(writerSet()))[0]!;
1790
+ expect(c.levels!.map((l) => l.detail)).toEqual([
1791
+ LABELS.monthly("$2,200"),
1792
+ LABELS.monthly("$4,400"),
1793
+ LABELS.monthly("$6,600"),
1794
+ ]);
1795
+ expect(c).not.toHaveProperty("detail");
1796
+ });
1797
+
1798
+ it("a point with no nickname is labelled by its price phrase, with no detail repeating it", () => {
1799
+ const set = writerSet(([w]) => [
1800
+ { ...w!, prices: w!.prices.map(({ label, ...p }) => (p.plan === "writer-8" ? p : { ...p, label: label! })) },
1801
+ ]);
1802
+ const level = plansOf(mapped(set))[0]!.levels![1]!;
1803
+ expect(level.label).toBe(LABELS.monthly("$4,400"));
1804
+ expect(level).not.toHaveProperty("detail");
1805
+ });
1806
+
1807
+ it("a repeated nickname falls back to the price phrase, so the labels stay distinct", () => {
1808
+ const set = writerSet(([w]) => [{ ...w!, prices: w!.prices.map((p) => ({ ...p, label: "Same" })) }]);
1809
+ expect(plansOf(mapped(set))[0]!.levels!.map((l) => l.label)).toEqual([
1810
+ "Same",
1811
+ LABELS.monthly("$4,400"),
1812
+ LABELS.monthly("$6,600"),
1813
+ ]);
1814
+ });
1815
+
1816
+ it("the mapped section parses with the section schema", () => {
1817
+ expect(PricingSectionDataSchema.safeParse(mapped(writerSet()).plans).success).toBe(true);
1818
+ });
1819
+ });
1820
+
1821
+ describe("offeringsPricing — changing points changes the amount and the link only (#12210 D6 rule 1, AC-2)", () => {
1822
+ it("levels differ only in price, links, offerPrices, key, label and detail", () => {
1823
+ const levels = plansOf(mapped(writerSet()))[0]!.levels!;
1824
+ const rest = levels.map((level) => {
1825
+ const {
1826
+ price: _p,
1827
+ annualCtaHref: _a,
1828
+ annualPriceNote: _n,
1829
+ offerPrices: _o,
1830
+ key: _k,
1831
+ label: _l,
1832
+ detail: _d,
1833
+ cta,
1834
+ ...fields
1835
+ } = level as typeof level & { offerPrices?: unknown };
1836
+ return { ...fields, cta: { label: cta.label } };
1837
+ });
1838
+ expect(rest[1]).toEqual(rest[0]);
1839
+ expect(rest[2]).toEqual(rest[0]);
1840
+ expect(rest[0]).toMatchObject({ description: "Writing, done", features: ["Edited"] });
1841
+ expect(levels.map((l) => l.cta.href)).toEqual([
1842
+ hrefFor("writer-4_monthly"),
1843
+ hrefFor("writer-8_monthly"),
1844
+ hrefFor("writer-12_monthly"),
1845
+ ]);
1846
+ expect(levels.map((l) => l.price.monthly)).toEqual([
1847
+ LABELS.monthly("$2,200"),
1848
+ LABELS.monthly("$4,400"),
1849
+ LABELS.monthly("$6,600"),
1850
+ ]);
1851
+ });
1852
+ });
1853
+
1854
+ describe("offeringsPricing — a tier mixes products and price points (#12210 D6 rule 4, AC-3)", () => {
1855
+ const mixed = (editorOrder: number) =>
1856
+ writerSet(([w]) => [
1857
+ { ...w!, tier: "Writing", ailkOrder: 10 },
1858
+ product("editor", "plan", [price("editor", "monthly", 150000, "usd")], {
1859
+ tier: "Writing",
1860
+ ailkOrder: editorOrder,
1861
+ description: "Editing only",
1862
+ marketingFeatures: ["One editor"],
1863
+ }),
1864
+ ]);
1865
+
1866
+ it("one card titled by the tier, the points in product then point order, each with its own product's text", () => {
1867
+ const cards = plansOf(tiers(mixed(20)));
1868
+ expect(cards).toHaveLength(1);
1869
+ const c = cards[0]!;
1870
+ expect(c.name).toBe("Writing");
1871
+ expect(c.levels!.map((l) => l.key)).toEqual(["writer-4", "writer-8", "writer-12", "editor"]);
1872
+ expect(c.levels!.map((l) => l.description)).toEqual(["Writing, done", "Writing, done", "Writing, done", "Editing only"]);
1873
+ expect(c.levels!.map((l) => l.features)).toEqual([["Edited"], ["Edited"], ["Edited"], ["One editor"]]);
1874
+ expect(c.levels![3]).not.toHaveProperty("detail");
1875
+ });
1876
+
1877
+ it("orders the members by ailk_order, keeping a product's points together", () => {
1878
+ expect(plansOf(tiers(mixed(5)))[0]!.levels!.map((l) => l.key)).toEqual([
1879
+ "editor",
1880
+ "writer-4",
1881
+ "writer-8",
1882
+ "writer-12",
1883
+ ]);
1884
+ });
1885
+ });
1886
+
1887
+ describe("offeringsPricing — a price added in Stripe is a level (#12210 AC-4)", () => {
1888
+ it("a fourth point gives a fourth level, with no page input changed", () => {
1889
+ const set = writerSet(([w]) => [{ ...w!, prices: [...w!.prices, pointPrice("writer-16", 880000, "16 pieces/mo")] }]);
1890
+ const c = plansOf(mapped(set))[0]!;
1891
+ expect(c.levels!.map((l) => l.key)).toEqual(["writer-4", "writer-8", "writer-12", "writer-16"]);
1892
+ });
1893
+ });
1894
+
1895
+ describe("offeringsPricing — twenty price points (#12210 D6 rule 6, AC-5)", () => {
1896
+ it("one card with twenty levels on the select control, each with its own checkout link", () => {
1897
+ const set = writerSet(() => [pointsProduct(20)]);
1898
+ const c = plansOf(mapped(set))[0]!;
1899
+ expect(c.levels).toHaveLength(20);
1900
+ expect(c.levelSwitchControl).toBe("select");
1901
+ expect(new Set(c.levels!.map((l) => l.cta.href)).size).toBe(20);
1902
+ expect(c.levels![19]!.cta.href).toBe(hrefFor("p-20_monthly"));
1903
+ expect(PricingSectionDataSchema.safeParse(mapped(set).plans).success).toBe(true);
1904
+ });
1905
+
1906
+ it("a card of four points follows the section's control", () => {
1907
+ const c = plansOf(mapped(writerSet(() => [pointsProduct(4)])))[0]!;
1908
+ expect(c.levels).toHaveLength(4);
1909
+ expect(c).not.toHaveProperty("levelSwitchControl");
1910
+ });
1911
+ });
1912
+
1913
+ describe("offeringsPricing — a one-point product is exactly as before (#12210 AC-6)", () => {
1914
+ it("its card has no levels, no detail and no control", () => {
1915
+ const growth = card(mapped(), "growth");
1916
+ expect(growth).not.toHaveProperty("levels");
1917
+ expect(growth).not.toHaveProperty("levelSwitchControl");
1918
+ expect(JSON.stringify(mapped())).not.toContain('"detail"');
1919
+ });
1920
+ });
1921
+
1922
+ describe("offeringsPricing — a product is named by any of its slugs (#12210 D6 rules 7–8)", () => {
1923
+ it("a page naming a later point keeps the product; excluding one drops it", () => {
1924
+ const set = writerSet((o) => [...o, ...fixtureOfferings().filter((p) => p.plan === "growth")]);
1925
+ expect(plansOf(offeringsPricing(set, { ...OPTIONS, plans: ["writer-8"] })!).map((c) => c.key)).toEqual(["writer-4"]);
1926
+ expect(plansOf(offeringsPricing(set, { ...OPTIONS, exclude: ["writer-12"] })!).map((c) => c.key)).toEqual(["growth"]);
1927
+ });
1928
+
1929
+ it("an offeringGroups level names one point", () => {
1930
+ const result = offeringsPricing(writerSet(), {
1931
+ ...OPTIONS,
1932
+ plans: ["writer-8", "writer-12"],
1933
+ levelGroups: [
1934
+ {
1935
+ key: "writers",
1936
+ name: "Writers",
1937
+ levels: [
1938
+ { label: "Eight", plan: "writer-8" },
1939
+ { label: "Twelve", plan: "writer-12" },
1940
+ ],
1941
+ },
1942
+ ],
1943
+ })!;
1944
+ const c = plansOf(result)[0]!;
1945
+ expect(c.levels!.map((l) => [l.label, l.cta.href])).toEqual([
1946
+ ["Eight", hrefFor("writer-8_monthly")],
1947
+ ["Twelve", hrefFor("writer-12_monthly")],
1948
+ ]);
1949
+ });
1950
+
1951
+ it("a bundle whose required product has points gives no card", () => {
1952
+ const set = writerSet((o) => [
1953
+ ...o,
1954
+ product("kickoff", "plan", [price("kickoff", "once", 50000, "usd")], { requires: "writer-8" }),
1955
+ ]);
1956
+ // The required product is sold only inside its bundle (#10028 decision 6),
1957
+ // and the bundle sells no ambiguous recurring Price — so neither shows.
1958
+ expect(mapped(set).plans).toBeNull();
1959
+ });
1960
+
1961
+ it("features-and-plans never splits a lone card with levels", () => {
1962
+ const set = writerSet(([w]) => [
1963
+ { ...w!, prices: [...w!.prices.slice(0, 1), { ...price("writer-4", "yearly", 2200000, "usd"), label: "4 pieces/mo" }, ...w!.prices.slice(1)] },
1964
+ ]);
1965
+ const plans = offeringsPricing(set, { ...OPTIONS, layout: "features-and-plans" })!.plans!.plans;
1966
+ expect(plans).toHaveLength(1);
1967
+ expect(plans[0]!.levels).toHaveLength(3);
1968
+ });
1969
+ });
1970
+
1971
+ describe("offeringsPricing — a twenty-one-level tier keeps twenty (#12210 D6 rule 6, AC-8)", () => {
1972
+ it("drops the twenty-first level, so no level names it", () => {
1973
+ const set = writerSet(() => [
1974
+ product("solo", "plan", [price("solo", "monthly", 500, "usd")], { tier: "Big", ailkOrder: 1 }),
1975
+ pointsProduct(20, { tier: "Big", ailkOrder: 2 }),
1976
+ ]);
1977
+ const cards = plansOf(tiers(set));
1978
+ expect(cards).toHaveLength(1);
1979
+ const keys = cards[0]!.levels!.map((l) => l.key);
1980
+ expect(keys).toHaveLength(20);
1981
+ expect(keys[19]).toBe("p-19");
1982
+ expect(keys).not.toContain("p-20");
1983
+ expect(cards[0]!.levelSwitchControl).toBe("select");
1984
+ });
1985
+ });
1986
+
1987
+ describe("price points under offeringGroups and in a long tier (#12210 D6 rules 4–6, D12)", () => {
1988
+ it("a group naming later points of the Recommended product is highlighted", () => {
1989
+ const set = writerSet((offerings) => [writer({ recommended: true }), ...offerings.slice(1)]);
1990
+ const groups = [
1991
+ { key: "writing", name: "Writing", levels: [{ label: "Eight", plan: "writer-8" }, { label: "Twelve", plan: "writer-12" }] },
1992
+ { key: "solo", name: "Solo", levels: [{ label: "Twelve", plan: "writer-12" }, { label: "Four", plan: "writer-4" }] },
1993
+ ];
1994
+ const cards = plansOf(offeringsPricing(set, { ...OPTIONS, levelGroups: groups })!);
1995
+ expect(cards.map((c) => [c.key, c.highlighted === true])).toEqual([
1996
+ ["writing", true],
1997
+ ["solo", true],
1998
+ ]);
1999
+ expect(cards[0]!.levels!.map((l) => l.key)).toEqual(["writer-8", "writer-12"]);
2000
+ });
2001
+
2002
+ it("a tier with a multi-point member keeps every member, up to 20 levels, on the select", () => {
2003
+ const tierOf = (n: number) =>
2004
+ product(`member-${n}`, "plan", [price(`member-${n}`, "monthly", 1000 * n, "usd")], { tier: "Writing", ailkOrder: 20 + n });
2005
+ const set = writerSet(() => [writer({ tier: "Writing", ailkOrder: 10 }), tierOf(1), tierOf(2), tierOf(3), tierOf(4)]);
2006
+ const card = plansOf(offeringsPricing(set, { ...OPTIONS, tiers: true })!)[0]!;
2007
+ expect(card.levels!.map((l) => l.key)).toEqual([
2008
+ "writer-4",
2009
+ "writer-8",
2010
+ "writer-12",
2011
+ "member-1",
2012
+ "member-2",
2013
+ "member-3",
2014
+ "member-4",
2015
+ ]);
2016
+ expect(card.levelSwitchControl).toBe("select");
2017
+ });
2018
+ });