marketingTouchActions.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { describe, expect, it } from "vitest";
  2. import { marketingActionSchema } from "@zcode/shared";
  3. describe("marketing navigation and copy contract", () => {
  4. it.each([
  5. "general",
  6. "appearance",
  7. "models",
  8. "browser",
  9. "computer_use",
  10. "memory",
  11. "subagents",
  12. "plugins",
  13. "mcp",
  14. "skills",
  15. "commands",
  16. "hooks",
  17. "usage",
  18. ])("accepts section %s", (section) => {
  19. expect(
  20. marketingActionSchema.safeParse({ type: "navigate", args: { page: "settings", section } })
  21. .success,
  22. ).toBe(true);
  23. });
  24. it.each([
  25. { page: "settings" },
  26. { page: "upgrade" },
  27. { page: "rewards" },
  28. { page: "settings", section: "models", provider_id: "provider" },
  29. { page: "plugin_marketplace" },
  30. { page: "plugin_marketplace", plugin_id: "plugin@market" },
  31. ])("accepts %j", (args) => {
  32. expect(marketingActionSchema.safeParse({ type: "navigate", args }).success).toBe(true);
  33. });
  34. it.each([
  35. { page: "settings", section: "automations" },
  36. { page: "upgrade", provider_id: "builtin:bigmodel" },
  37. { page: "upgrade", plan_id: "plan" },
  38. { page: "upgrade", section: "models" },
  39. { page: "referrals" },
  40. { page: "rewards", url: "https://example.com" },
  41. { page: "rewards", section: "models" },
  42. { page: "settings", provider_id: "provider" },
  43. { page: "settings", section: "general", provider_id: "provider" },
  44. { page: "settings", plugin_id: "plugin@market" },
  45. { page: "plugin_marketplace", section: "plugins" },
  46. { page: "plugin_marketplace", plugin_id: "plugin" },
  47. { page: "plugin_marketplace", plugin_id: "@market" },
  48. { page: "plugin_marketplace", query: "search" },
  49. { page: "settings", section: null },
  50. { page: "settings", section: "models", provider_id: "x".repeat(129) },
  51. ])("rejects %j", (args) => {
  52. expect(marketingActionSchema.safeParse({ type: "navigate", args }).success).toBe(false);
  53. });
  54. it("preserves plaintext exactly and enforces bounds", () => {
  55. const text = " <b>hello</b>\n world ";
  56. expect(marketingActionSchema.parse({ type: "copy_text", args: { text } })).toEqual({
  57. type: "copy_text",
  58. args: { text },
  59. });
  60. for (const args of [{ text: " \n" }, { text: "x".repeat(20001) }, { text, extra: true }]) {
  61. expect(marketingActionSchema.safeParse({ type: "copy_text", args }).success).toBe(false);
  62. }
  63. expect(
  64. marketingActionSchema.safeParse({ type: "copy_text", args: { text: "x".repeat(20000) } })
  65. .success,
  66. ).toBe(true);
  67. });
  68. });