create-abcart-theme 0.10.1 → 1.0.0

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.
Files changed (251) hide show
  1. package/CHANGELOG.md +133 -127
  2. package/LICENSE +202 -202
  3. package/NOTICE +2 -2
  4. package/README.md +65 -65
  5. package/bin/create-abcart-theme.mjs +4 -4
  6. package/package.json +49 -49
  7. package/src/args.mjs +113 -113
  8. package/src/banner.mjs +21 -21
  9. package/src/cli.mjs +119 -119
  10. package/src/create.mjs +85 -82
  11. package/src/package-manager.mjs +32 -32
  12. package/src/style.mjs +17 -17
  13. package/templates/default/.agents/skills/{wocart-docs → abcart-docs}/SKILL.md +146 -146
  14. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/SKILL.md +58 -58
  15. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/inputs-and-rights.md +47 -47
  16. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/layout-rtl-and-phone.md +36 -36
  17. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/measure-the-design.md +60 -60
  18. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/tokens-sections-content.md +103 -103
  19. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/verify-and-report.md +102 -102
  20. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/scripts/compare-design.cjs +230 -230
  21. package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/scripts/qa-pages.cjs +219 -219
  22. package/templates/default/.agents/skills/shopify-theme-asset-collector/SKILL.md +125 -125
  23. package/templates/default/.agents/skills/shopify-theme-asset-collector/scripts/collect_public_assets.py +370 -370
  24. package/templates/default/.dev.vars.example +12 -12
  25. package/templates/default/AGENTS.md +240 -240
  26. package/templates/default/README.md +184 -184
  27. package/templates/default/_gitignore +11 -11
  28. package/templates/default/astro.config.mjs +85 -85
  29. package/templates/default/package.json +36 -36
  30. package/templates/default/public/fonts/OFL.txt +96 -96
  31. package/templates/default/src/actions/index.ts +22 -22
  32. package/templates/default/src/components/cart/AddToCartButton.astro +45 -45
  33. package/templates/default/src/components/cart/CartDrawer.astro +47 -47
  34. package/templates/default/src/components/cart/CartSummary.astro +11 -11
  35. package/templates/default/src/components/cart/FreeShipping.astro +7 -7
  36. package/templates/default/src/components/checkout/CheckoutMain.astro +29 -29
  37. package/templates/default/src/components/checkout/OrderForm.astro +280 -280
  38. package/templates/default/src/components/checkout/ThankYouMain.astro +68 -68
  39. package/templates/default/src/components/landing/LandingImages.astro +51 -51
  40. package/templates/default/src/components/landing/LandingOrder.astro +46 -46
  41. package/templates/default/src/components/landing/LandingProduct.astro +41 -41
  42. package/templates/default/src/components/listing/ListingMain.astro +93 -93
  43. package/templates/default/src/components/listing/PageMain.astro +52 -52
  44. package/templates/default/src/components/listing/Pagination.astro +31 -31
  45. package/templates/default/src/components/listing/SortControl.astro +35 -35
  46. package/templates/default/src/components/product/BuyBox.astro +96 -96
  47. package/templates/default/src/components/product/Description.astro +24 -24
  48. package/templates/default/src/components/product/Gallery.astro +66 -66
  49. package/templates/default/src/components/product/MobileBuyBar.astro +29 -29
  50. package/templates/default/src/components/product/OfferChoice.astro +66 -66
  51. package/templates/default/src/components/product/ProductMain.astro +40 -40
  52. package/templates/default/src/components/product/ProductReviews.astro +72 -72
  53. package/templates/default/src/components/product/RelatedProducts.astro +30 -30
  54. package/templates/default/src/components/product/blocks/BenefitsBlock.astro +13 -13
  55. package/templates/default/src/components/product/blocks/CollapsibleBlock.astro +20 -20
  56. package/templates/default/src/components/product/blocks/DescriptionBlock.astro +19 -19
  57. package/templates/default/src/components/product/blocks/DetailsBlock.astro +33 -33
  58. package/templates/default/src/components/product/blocks/GalleryBlock.astro +12 -12
  59. package/templates/default/src/components/product/blocks/OrderBlock.astro +30 -30
  60. package/templates/default/src/components/product/blocks/PriceBlock.astro +23 -23
  61. package/templates/default/src/components/product/blocks/RatingBlock.astro +16 -16
  62. package/templates/default/src/components/product/blocks/StockBlock.astro +22 -22
  63. package/templates/default/src/components/product/blocks/TextBlock.astro +11 -11
  64. package/templates/default/src/components/product/blocks/TitleBlock.astro +20 -20
  65. package/templates/default/src/components/reviews/ReviewCard.astro +46 -46
  66. package/templates/default/src/components/reviews/ReviewForm.astro +113 -113
  67. package/templates/default/src/components/reviews/VoiceNote.astro +60 -60
  68. package/templates/default/src/components/sections/CollectionCards.astro +65 -65
  69. package/templates/default/src/components/sections/Countdown.astro +57 -57
  70. package/templates/default/src/components/sections/Faq.astro +44 -44
  71. package/templates/default/src/components/sections/FeaturedProduct.astro +71 -71
  72. package/templates/default/src/components/sections/Hero.astro +99 -99
  73. package/templates/default/src/components/sections/ImageBanner.astro +46 -46
  74. package/templates/default/src/components/sections/ProductGrid.astro +47 -47
  75. package/templates/default/src/components/sections/RichText.astro +35 -35
  76. package/templates/default/src/components/sections/Steps.astro +46 -46
  77. package/templates/default/src/components/sections/Testimonials.astro +57 -57
  78. package/templates/default/src/components/shell/Footer.astro +80 -80
  79. package/templates/default/src/components/shell/Header.astro +89 -89
  80. package/templates/default/src/components/shell/LanguageMenu.astro +33 -33
  81. package/templates/default/src/components/shell/MobileMenu.astro +65 -65
  82. package/templates/default/src/components/shell/SearchDialog.astro +19 -19
  83. package/templates/default/src/components/shell/TopBar.astro +54 -54
  84. package/templates/default/src/components/shell/WhatsAppWidget.astro +111 -111
  85. package/templates/default/src/components/store/ContactMain.astro +79 -79
  86. package/templates/default/src/components/store/SearchMain.astro +56 -56
  87. package/templates/default/src/components/store/TrackOrderMain.astro +161 -161
  88. package/templates/default/src/components/surface/Area.astro +20 -20
  89. package/templates/default/src/components/surface/PreviewBridge.astro +24 -24
  90. package/templates/default/src/components/surface/Sections.astro +35 -35
  91. package/templates/default/src/components/ui/Breadcrumbs.astro +36 -36
  92. package/templates/default/src/components/ui/Button.astro +45 -45
  93. package/templates/default/src/components/ui/EditorPlaceholder.astro +24 -24
  94. package/templates/default/src/components/ui/Icon.astro +93 -93
  95. package/templates/default/src/components/ui/Logo.astro +36 -36
  96. package/templates/default/src/components/ui/Photo.astro +46 -46
  97. package/templates/default/src/components/ui/Price.astro +24 -24
  98. package/templates/default/src/components/ui/ProductCard.astro +41 -41
  99. package/templates/default/src/components/ui/Rating.astro +22 -22
  100. package/templates/default/src/components/ui/Section.astro +34 -34
  101. package/templates/default/src/components/ui/SectionHeading.astro +19 -19
  102. package/templates/default/src/env.d.ts +23 -23
  103. package/templates/default/src/layouts/StoreLayout.astro +145 -145
  104. package/templates/default/src/lib/browser-copy.ts +37 -37
  105. package/templates/default/src/lib/context.ts +89 -89
  106. package/templates/default/src/lib/coupon-notice.ts +47 -47
  107. package/templates/default/src/lib/i18n.ts +32 -32
  108. package/templates/default/src/lib/images.ts +38 -38
  109. package/templates/default/src/lib/listing-query.ts +41 -41
  110. package/templates/default/src/lib/money.ts +16 -16
  111. package/templates/default/src/lib/motion.ts +16 -16
  112. package/templates/default/src/lib/nav.ts +26 -26
  113. package/templates/default/src/lib/offer-tiles.ts +105 -105
  114. package/templates/default/src/lib/order-outcome.ts +66 -66
  115. package/templates/default/src/lib/otp-message.ts +21 -21
  116. package/templates/default/src/lib/products.ts +38 -38
  117. package/templates/default/src/lib/review-refusals.ts +31 -31
  118. package/templates/default/src/lib/store.ts +31 -31
  119. package/templates/default/src/lib/whatsapp.ts +29 -29
  120. package/templates/default/src/middleware.ts +23 -23
  121. package/templates/default/src/pages/404.astro +22 -22
  122. package/templates/default/src/pages/{wocart-preview.astro → abcart-preview.astro} +43 -43
  123. package/templates/default/src/pages/{wocart-revalidate.ts → abcart-revalidate.ts} +10 -10
  124. package/templates/default/src/pages/{wocart-styles.css.ts → abcart-styles.css.ts} +5 -5
  125. package/templates/default/src/pages/{wocart-theme.json.ts → abcart-theme.json.ts} +5 -5
  126. package/templates/default/src/pages/api/abandoned/convert.ts +4 -4
  127. package/templates/default/src/pages/api/abandoned/upsert.ts +4 -4
  128. package/templates/default/src/pages/api/cart/validate.ts +4 -4
  129. package/templates/default/src/pages/api/communes/[wilayaId].ts +4 -4
  130. package/templates/default/src/pages/api/otp/send.ts +4 -4
  131. package/templates/default/src/pages/api/otp/verify.ts +4 -4
  132. package/templates/default/src/pages/api/reviews/[productId].ts +3 -3
  133. package/templates/default/src/pages/api/reviews/eligibility.ts +3 -3
  134. package/templates/default/src/pages/api/reviews/submit.ts +3 -3
  135. package/templates/default/src/pages/api/reviews/upload.ts +3 -3
  136. package/templates/default/src/pages/category/[slug].astro +20 -20
  137. package/templates/default/src/pages/checkout.astro +25 -25
  138. package/templates/default/src/pages/collections/[handle].astro +20 -20
  139. package/templates/default/src/pages/contact.astro +17 -17
  140. package/templates/default/src/pages/index.astro +9 -9
  141. package/templates/default/src/pages/lp/[slug].astro +47 -47
  142. package/templates/default/src/pages/pages/[slug].astro +16 -16
  143. package/templates/default/src/pages/products/[handle].astro +37 -37
  144. package/templates/default/src/pages/products/index.astro +15 -15
  145. package/templates/default/src/pages/robots.txt.ts +9 -9
  146. package/templates/default/src/pages/search.astro +19 -19
  147. package/templates/default/src/pages/sitemap.xml.ts +12 -12
  148. package/templates/default/src/pages/thank-you.astro +33 -33
  149. package/templates/default/src/pages/track-order.astro +17 -17
  150. package/templates/default/src/scripts/cart.ts +371 -371
  151. package/templates/default/src/scripts/checkout/coupon.ts +96 -96
  152. package/templates/default/src/scripts/checkout/delivery.ts +86 -86
  153. package/templates/default/src/scripts/checkout/form.ts +54 -54
  154. package/templates/default/src/scripts/checkout/otp.ts +106 -106
  155. package/templates/default/src/scripts/checkout/picker.ts +169 -169
  156. package/templates/default/src/scripts/checkout/quote.ts +169 -169
  157. package/templates/default/src/scripts/checkout/submit.ts +113 -113
  158. package/templates/default/src/scripts/checkout/tracking.ts +74 -74
  159. package/templates/default/src/scripts/countdown.ts +29 -29
  160. package/templates/default/src/scripts/events.ts +4 -4
  161. package/templates/default/src/scripts/hero.ts +49 -49
  162. package/templates/default/src/scripts/listing.ts +13 -13
  163. package/templates/default/src/scripts/order-form.ts +100 -100
  164. package/templates/default/src/scripts/product.ts +306 -306
  165. package/templates/default/src/scripts/public-config.ts +79 -79
  166. package/templates/default/src/scripts/reviews.ts +358 -358
  167. package/templates/default/src/scripts/site.ts +131 -131
  168. package/templates/default/src/scripts/thank-you.ts +11 -11
  169. package/templates/default/src/scripts/voice-note.ts +94 -94
  170. package/templates/default/src/styles/base.css +1030 -1030
  171. package/templates/default/src/styles/checkout.css +1111 -1111
  172. package/templates/default/src/styles/global.css +12 -12
  173. package/templates/default/src/styles/product.css +871 -871
  174. package/templates/default/src/styles/reviews.css +533 -533
  175. package/templates/default/src/styles/sections.css +931 -931
  176. package/templates/default/src/styles/shell.css +970 -970
  177. package/templates/default/src/styles/tokens.css +583 -583
  178. package/templates/default/src/theme/api-routes.ts +10 -10
  179. package/templates/default/src/theme/content/catalog.ts +117 -117
  180. package/templates/default/src/theme/content/checkout.ts +168 -168
  181. package/templates/default/src/theme/content/editor.ts +21 -21
  182. package/templates/default/src/theme/content/index.ts +45 -45
  183. package/templates/default/src/theme/content/reviews.ts +76 -76
  184. package/templates/default/src/theme/content/shell.ts +59 -59
  185. package/templates/default/src/theme/content/types.ts +12 -12
  186. package/templates/default/src/theme/documents/catalog.json +11 -11
  187. package/templates/default/src/theme/documents/category.json +11 -11
  188. package/templates/default/src/theme/documents/checkout.json +11 -11
  189. package/templates/default/src/theme/documents/collection.json +11 -11
  190. package/templates/default/src/theme/documents/contact.json +11 -11
  191. package/templates/default/src/theme/documents/footer.area.json +11 -11
  192. package/templates/default/src/theme/documents/header.area.json +16 -16
  193. package/templates/default/src/theme/documents/home.json +313 -313
  194. package/templates/default/src/theme/documents/landing.json +8 -8
  195. package/templates/default/src/theme/documents/page.json +11 -11
  196. package/templates/default/src/theme/documents/product.json +125 -125
  197. package/templates/default/src/theme/documents/search.json +11 -11
  198. package/templates/default/src/theme/documents/thank-you.json +11 -11
  199. package/templates/default/src/theme/documents/track-order.json +11 -11
  200. package/templates/default/src/theme/fields.ts +61 -61
  201. package/templates/default/src/theme/key.ts +11 -11
  202. package/templates/default/src/theme/labels.ts +231 -231
  203. package/templates/default/src/theme/locales.ts +11 -11
  204. package/templates/default/src/theme/palette.ts +14 -14
  205. package/templates/default/src/theme/sections/collection-cards.ts +65 -65
  206. package/templates/default/src/theme/sections/faq.ts +74 -74
  207. package/templates/default/src/theme/sections/featured-product.ts +42 -42
  208. package/templates/default/src/theme/sections/hero.ts +47 -47
  209. package/templates/default/src/theme/sections/image-banner.ts +25 -25
  210. package/templates/default/src/theme/sections/index.ts +40 -40
  211. package/templates/default/src/theme/sections/landing.ts +150 -150
  212. package/templates/default/src/theme/sections/listing.ts +84 -84
  213. package/templates/default/src/theme/sections/product-grid.ts +42 -42
  214. package/templates/default/src/theme/sections/product.ts +297 -297
  215. package/templates/default/src/theme/sections/rich-text.ts +39 -39
  216. package/templates/default/src/theme/sections/shared.ts +54 -54
  217. package/templates/default/src/theme/sections/shell.ts +85 -85
  218. package/templates/default/src/theme/sections/store-pages.ts +101 -101
  219. package/templates/default/src/theme/sections/testimonials.ts +61 -61
  220. package/templates/default/src/theme/sections/thank-you.ts +35 -35
  221. package/templates/default/src/theme/settings.ts +124 -124
  222. package/templates/default/src/theme/theme.ts +65 -65
  223. package/templates/default/tests/fixtures/canvas-tote.json +62 -62
  224. package/templates/default/tests/fixtures/linen-shirt.json +128 -128
  225. package/templates/default/tests/unit/checkout.test.ts +241 -241
  226. package/templates/default/tests/unit/contract.test.ts +170 -169
  227. package/templates/default/tests/unit/contrast.test.ts +68 -68
  228. package/templates/default/tests/unit/copy.test.ts +101 -101
  229. package/templates/default/tests/unit/design-values.test.ts +95 -95
  230. package/templates/default/tests/unit/editability.test.ts +180 -180
  231. package/templates/default/tests/unit/fixtures.ts +91 -91
  232. package/templates/default/tests/unit/footer.test.ts +54 -54
  233. package/templates/default/tests/unit/guards.test.ts +340 -340
  234. package/templates/default/tests/unit/images.test.ts +26 -26
  235. package/templates/default/tests/unit/landing.test.ts +151 -151
  236. package/templates/default/tests/unit/languages.test.ts +42 -42
  237. package/templates/default/tests/unit/middleware.test.ts +53 -53
  238. package/templates/default/tests/unit/offer-tiles.test.ts +75 -75
  239. package/templates/default/tests/unit/render.ts +38 -38
  240. package/templates/default/tests/unit/reviews.test.ts +25 -25
  241. package/templates/default/tests/unit/rules.test.ts +59 -59
  242. package/templates/default/tests/unit/source.ts +75 -75
  243. package/templates/default/tests/unit/store-pages.test.ts +147 -147
  244. package/templates/default/tests/unit/studio.test.ts +202 -202
  245. package/templates/default/tests/unit/testimonials.test.ts +52 -52
  246. package/templates/default/tests/unit/thank-you.test.ts +52 -52
  247. package/templates/default/tests/unit/tracking.test.ts +29 -29
  248. package/templates/default/tests/unit/voice-note.test.ts +42 -42
  249. package/templates/default/tsconfig.json +13 -13
  250. package/templates/default/vitest.config.ts +15 -15
  251. package/templates/default/wrangler.jsonc +16 -16
@@ -1,202 +1,202 @@
1
- /**
2
- * What Wocart Studio needs from this theme, checked with real Ed25519 keys
3
- * the way Studio signs them: the manifest it reads, the preview it frames and
4
- * the revalidation a publish sends. A token for another store, another theme
5
- * or the other use is refused; a deployment without the key answers 404.
6
- */
7
- import { readFileSync, readdirSync } from "node:fs";
8
- import { join, relative, resolve, sep } from "node:path";
9
- import { beforeAll, describe, expect, it, vi } from "vitest";
10
- import type { APIContext, MiddlewareNext } from "astro";
11
- import { experimental_AstroContainer as AstroContainer } from "astro/container";
12
- import { THEME_KEY, THEME_VERSION } from "../../src/theme/key";
13
- import { storeContext, testConfig } from "./fixtures";
14
-
15
- const env = vi.hoisted(() => ({ WOCART_PREVIEW_KEY: undefined as string | undefined }));
16
- vi.mock("astro:env/server", () => ({
17
- COD_SERVER_URL: "http://localhost:8787",
18
- STORE_API_KEY: "test-key",
19
- get WOCART_PREVIEW_KEY() {
20
- return env.WOCART_PREVIEW_KEY;
21
- },
22
- }));
23
-
24
- const revalidate = await import("../../src/pages/wocart-revalidate");
25
- const manifestRoute = await import("../../src/pages/wocart-theme.json");
26
- const { onRequest } = await import("../../src/middleware");
27
- const { default: PreviewPage } = await import("../../src/pages/wocart-preview.astro");
28
-
29
- const STORE = "https://boutique.test";
30
- const EDITOR = "https://studio.example.test";
31
- let privateKey: CryptoKey;
32
-
33
- const b64url = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
34
- const encodeJson = (value: unknown) => b64url(new TextEncoder().encode(JSON.stringify(value)));
35
- async function sign(payload: Record<string, unknown>) {
36
- const head = encodeJson({ alg: "EdDSA", typ: "JWT" });
37
- const body = encodeJson(payload);
38
- const signature = new Uint8Array(await crypto.subtle.sign({ name: "Ed25519" }, privateKey, new TextEncoder().encode(`${head}.${body}`)));
39
- return `${head}.${body}.${b64url(signature)}`;
40
- }
41
- const now = () => Math.floor(Date.now() / 1000);
42
- const previewPass = (over: Record<string, unknown> = {}) => ({ aud: STORE, theme: THEME_KEY, editor: EDITOR, iat: now(), exp: now() + 600, ...over });
43
- const revalidation = (over: Record<string, unknown> = {}) => ({ aud: STORE, theme: THEME_KEY, use: "revalidate", iat: now(), exp: now() + 120, ...over });
44
-
45
- async function withoutKey<T>(run: () => Promise<T>): Promise<T> {
46
- const key = env.WOCART_PREVIEW_KEY;
47
- env.WOCART_PREVIEW_KEY = undefined;
48
- try {
49
- return await run();
50
- } finally {
51
- env.WOCART_PREVIEW_KEY = key;
52
- }
53
- }
54
-
55
- async function publish(authorization?: string) {
56
- const invalidate = vi.fn(async () => {});
57
- const request = new Request(`${STORE}/wocart-revalidate`, { method: "POST", headers: authorization ? { Authorization: authorization } : {} });
58
- const response = await revalidate.POST({ request, cache: { invalidate } } as unknown as APIContext);
59
- return { response, invalidate };
60
- }
61
-
62
- /** How Studio frames a preview: `GET /wocart-preview?token=…&surface=…`. */
63
- const previewRequest = (token?: string) => new Request(`${STORE}/wocart-preview?surface=home${token ? `&token=${token}` : ""}`);
64
-
65
- /** The preview as the theme's middleware opens it, against a store that answers its config. */
66
- async function openPreview(token?: string) {
67
- const fetchSpy = vi.spyOn(globalThis, "fetch").mockImplementation(async () => Response.json({ data: testConfig("ar") }));
68
- try {
69
- const request = previewRequest(token);
70
- const locals: Partial<App.Locals> = {};
71
- const next = vi.fn(async () => new Response("page"));
72
- const context = { isPrerendered: false, url: new URL(request.url), request, locals, redirect: () => new Response(null, { status: 302 }) };
73
- const response = await onRequest(context as unknown as APIContext, next as unknown as MiddlewareNext);
74
- return { response: response as Response, next, preview: locals.preview };
75
- } finally {
76
- fetchSpy.mockRestore();
77
- }
78
- }
79
-
80
- beforeAll(async () => {
81
- const pair = (await crypto.subtle.generateKey({ name: "Ed25519" }, true, ["sign", "verify"])) as CryptoKeyPair;
82
- privateKey = pair.privateKey;
83
- env.WOCART_PREVIEW_KEY = JSON.stringify(await crypto.subtle.exportKey("jwk", pair.publicKey));
84
- });
85
-
86
- describe("the manifest Studio reads", () => {
87
- it("names this theme and version, and is built once, at build time", async () => {
88
- const response = (manifestRoute.GET as () => Response)();
89
- const manifest = await response.json();
90
- expect(manifest).toMatchObject({ key: THEME_KEY, version: THEME_VERSION, preview: true });
91
- expect(manifestRoute.prerender).toBe(true);
92
- });
93
-
94
- it("carries the version package.json carries, so a release names one thing", () => {
95
- const pkg = JSON.parse(readFileSync(resolve(__dirname, "../../package.json"), "utf8"));
96
- expect(THEME_VERSION).toBe(pkg.version);
97
- });
98
- });
99
-
100
- describe("the preview Studio frames", () => {
101
- it("opens for a pass Studio signed for this store and theme", async () => {
102
- const { next, preview } = await openPreview(await sign(previewPass()));
103
- expect(next).toHaveBeenCalledWith();
104
- expect(preview?.claims.editor).toBe(EDITOR);
105
- expect(preview?.draft.surface).toBe("home");
106
- });
107
-
108
- it("refuses a pass for another theme, a revalidation token, or none", async () => {
109
- for (const token of [await sign(previewPass({ theme: "another-theme" })), await sign(revalidation()), undefined]) {
110
- const { response, next, preview } = await openPreview(token);
111
- expect(response.status).toBeGreaterThanOrEqual(400);
112
- expect(next).not.toHaveBeenCalled();
113
- expect(preview).toBeUndefined();
114
- }
115
- });
116
-
117
- it("renders the draft with every section marked and the editor's bridge, never cached", async () => {
118
- const token = await sign(previewPass());
119
- const { preview } = await openPreview(token);
120
- if (!preview) throw new Error("the pass was refused");
121
- const container = await AstroContainer.create();
122
- const response = await container.renderToResponse(PreviewPage, {
123
- request: previewRequest(token),
124
- locals: { store: storeContext("ar"), preview } as unknown as App.Locals,
125
- });
126
- const html = await response.text();
127
- expect(response.status).toBe(200);
128
- expect(response.headers.get("Cache-Control")).toMatch(/no-store/);
129
- expect(html.match(/<!--wocart:start id=/g)?.length ?? 0).toBeGreaterThan(3);
130
- expect(html).toContain(EDITOR);
131
- });
132
-
133
- it("is a 404 on a deployment without the key", async () => {
134
- const { response, preview } = await withoutKey(async () => openPreview(await sign(previewPass())));
135
- expect(response.status).toBe(404);
136
- expect(preview).toBeUndefined();
137
- });
138
- });
139
-
140
- describe("the revalidation a publish sends", () => {
141
- it("drops every cached page for the platform's revalidation token", async () => {
142
- const { response, invalidate } = await publish(`Bearer ${await sign(revalidation())}`);
143
- expect(response.status).toBe(204);
144
- expect(response.headers.get("Cache-Control")).toBe("no-store");
145
- expect(invalidate).toHaveBeenCalledWith({ tags: ["pages"] });
146
- });
147
-
148
- it("drops nothing for a preview pass, another store's or theme's token, or none", async () => {
149
- for (const token of [await sign(previewPass()), await sign(revalidation({ aud: "https://other.test" })), await sign(revalidation({ theme: "another-theme" }))]) {
150
- const { response, invalidate } = await publish(`Bearer ${token}`);
151
- expect(response.status).toBe(403);
152
- expect(invalidate).not.toHaveBeenCalled();
153
- }
154
- const { response, invalidate } = await publish();
155
- expect(response.status).toBe(401);
156
- expect(invalidate).not.toHaveBeenCalled();
157
- });
158
-
159
- it("is a 404 on a deployment without the key", async () => {
160
- const { response, invalidate } = await withoutKey(async () => publish(`Bearer ${await sign(revalidation())}`));
161
- expect(response.status).toBe(404);
162
- expect(invalidate).not.toHaveBeenCalled();
163
- });
164
-
165
- it("answers only POST, and is never prerendered", async () => {
166
- const response = (revalidate.ALL as () => Response)();
167
- expect(response.status).toBe(405);
168
- expect(revalidate.prerender).toBe(false);
169
- });
170
-
171
- it("reaches every cached page: each page route rule carries the SDK's pages tag, never its spelling", () => {
172
- const config = readFileSync(resolve(__dirname, "../../astro.config.mjs"), "utf8");
173
- const rules = config.slice(config.indexOf("routeRules: {"), config.indexOf("\n },", config.indexOf("routeRules: {")));
174
- const routes = [...rules.matchAll(/"([^"]+)":\s*\{[^}]*tags:\s*\[([^\]]*)\]/g)].map((match) => ({ route: match[1]!, tags: match[2]! }));
175
- expect(routes.length).toBeGreaterThan(5);
176
- expect(routes.filter((rule) => !rule.route.startsWith("/api/") && !rule.tags.includes("PAGES_CACHE_TAG")).map((rule) => rule.route)).toEqual([]);
177
- expect(rules).not.toContain('"pages"');
178
- expect(config).toMatch(/import \{ PAGES_CACHE_TAG \} from "@wocart\/storefront\/server";/);
179
- });
180
- });
181
-
182
- describe("what a publish reaches", () => {
183
- /** Routes a shopper's own request decides — a search, a basket, an order — and the contact page the siblings leave uncached too. */
184
- const UNCACHED = ["/search", "/checkout", "/thank-you", "/track-order", "/contact"];
185
- const config = readFileSync(resolve(__dirname, "../../astro.config.mjs"), "utf8");
186
- const rules = new Map([...config.matchAll(/"(\/[^"]*)":\s*\{[^}]*tags:\s*\[([^\]]*)\]/g)].map((match) => [match[1]!, match[2]!]));
187
- const pagesDir = resolve(__dirname, "../../src/pages");
188
- const walk = (dir: string): string[] => readdirSync(dir, { withFileTypes: true }).flatMap((entry) => (entry.isDirectory() ? walk(join(dir, entry.name)) : [join(dir, entry.name)]));
189
- /** Every route that renders a composed surface, as routeRules names it. */
190
- const composed = walk(pagesDir)
191
- .filter((file) => file.endsWith(".astro") && !file.endsWith("wocart-preview.astro") && readFileSync(file, "utf8").includes("<Sections"))
192
- .map((file) => `/${relative(pagesDir, file).split(sep).join("/").replace(/\.astro$/, "").replace(/(^|\/)index$/, "")}`);
193
-
194
- it("finds the composed routes, so the check means something", () => {
195
- expect(composed.length).toBeGreaterThanOrEqual(12);
196
- });
197
-
198
- it("caches every composed route under the pages tag, unless a shopper's own request decides the page", () => {
199
- expect(composed.filter((route) => !UNCACHED.includes(route) && !rules.get(route)?.includes("PAGES_CACHE_TAG"))).toEqual([]);
200
- expect(UNCACHED.filter((route) => !composed.includes(route) || rules.has(route))).toEqual([]);
201
- });
202
- });
1
+ /**
2
+ * What AbCart Studio needs from this theme, checked with real Ed25519 keys
3
+ * the way Studio signs them: the manifest it reads, the preview it frames and
4
+ * the revalidation a publish sends. A token for another store, another theme
5
+ * or the other use is refused; a deployment without the key answers 404.
6
+ */
7
+ import { readFileSync, readdirSync } from "node:fs";
8
+ import { join, relative, resolve, sep } from "node:path";
9
+ import { beforeAll, describe, expect, it, vi } from "vitest";
10
+ import type { APIContext, MiddlewareNext } from "astro";
11
+ import { experimental_AstroContainer as AstroContainer } from "astro/container";
12
+ import { THEME_KEY, THEME_VERSION } from "../../src/theme/key";
13
+ import { storeContext, testConfig } from "./fixtures";
14
+
15
+ const env = vi.hoisted(() => ({ ABCART_PREVIEW_KEY: undefined as string | undefined }));
16
+ vi.mock("astro:env/server", () => ({
17
+ COD_SERVER_URL: "http://localhost:8787",
18
+ STORE_API_KEY: "test-key",
19
+ get ABCART_PREVIEW_KEY() {
20
+ return env.ABCART_PREVIEW_KEY;
21
+ },
22
+ }));
23
+
24
+ const revalidate = await import("../../src/pages/abcart-revalidate");
25
+ const manifestRoute = await import("../../src/pages/abcart-theme.json");
26
+ const { onRequest } = await import("../../src/middleware");
27
+ const { default: PreviewPage } = await import("../../src/pages/abcart-preview.astro");
28
+
29
+ const STORE = "https://boutique.test";
30
+ const EDITOR = "https://studio.example.test";
31
+ let privateKey: CryptoKey;
32
+
33
+ const b64url = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
34
+ const encodeJson = (value: unknown) => b64url(new TextEncoder().encode(JSON.stringify(value)));
35
+ async function sign(payload: Record<string, unknown>) {
36
+ const head = encodeJson({ alg: "EdDSA", typ: "JWT" });
37
+ const body = encodeJson(payload);
38
+ const signature = new Uint8Array(await crypto.subtle.sign({ name: "Ed25519" }, privateKey, new TextEncoder().encode(`${head}.${body}`)));
39
+ return `${head}.${body}.${b64url(signature)}`;
40
+ }
41
+ const now = () => Math.floor(Date.now() / 1000);
42
+ const previewPass = (over: Record<string, unknown> = {}) => ({ aud: STORE, theme: THEME_KEY, editor: EDITOR, iat: now(), exp: now() + 600, ...over });
43
+ const revalidation = (over: Record<string, unknown> = {}) => ({ aud: STORE, theme: THEME_KEY, use: "revalidate", iat: now(), exp: now() + 120, ...over });
44
+
45
+ async function withoutKey<T>(run: () => Promise<T>): Promise<T> {
46
+ const key = env.ABCART_PREVIEW_KEY;
47
+ env.ABCART_PREVIEW_KEY = undefined;
48
+ try {
49
+ return await run();
50
+ } finally {
51
+ env.ABCART_PREVIEW_KEY = key;
52
+ }
53
+ }
54
+
55
+ async function publish(authorization?: string) {
56
+ const invalidate = vi.fn(async () => {});
57
+ const request = new Request(`${STORE}/abcart-revalidate`, { method: "POST", headers: authorization ? { Authorization: authorization } : {} });
58
+ const response = await revalidate.POST({ request, cache: { invalidate } } as unknown as APIContext);
59
+ return { response, invalidate };
60
+ }
61
+
62
+ /** How Studio frames a preview: `GET /abcart-preview?token=…&surface=…`. */
63
+ const previewRequest = (token?: string) => new Request(`${STORE}/abcart-preview?surface=home${token ? `&token=${token}` : ""}`);
64
+
65
+ /** The preview as the theme's middleware opens it, against a store that answers its config. */
66
+ async function openPreview(token?: string) {
67
+ const fetchSpy = vi.spyOn(globalThis, "fetch").mockImplementation(async () => Response.json({ data: testConfig("ar") }));
68
+ try {
69
+ const request = previewRequest(token);
70
+ const locals: Partial<App.Locals> = {};
71
+ const next = vi.fn(async () => new Response("page"));
72
+ const context = { isPrerendered: false, url: new URL(request.url), request, locals, redirect: () => new Response(null, { status: 302 }) };
73
+ const response = await onRequest(context as unknown as APIContext, next as unknown as MiddlewareNext);
74
+ return { response: response as Response, next, preview: locals.preview };
75
+ } finally {
76
+ fetchSpy.mockRestore();
77
+ }
78
+ }
79
+
80
+ beforeAll(async () => {
81
+ const pair = (await crypto.subtle.generateKey({ name: "Ed25519" }, true, ["sign", "verify"])) as CryptoKeyPair;
82
+ privateKey = pair.privateKey;
83
+ env.ABCART_PREVIEW_KEY = JSON.stringify(await crypto.subtle.exportKey("jwk", pair.publicKey));
84
+ });
85
+
86
+ describe("the manifest Studio reads", () => {
87
+ it("names this theme and version, and is built once, at build time", async () => {
88
+ const response = (manifestRoute.GET as () => Response)();
89
+ const manifest = await response.json();
90
+ expect(manifest).toMatchObject({ key: THEME_KEY, version: THEME_VERSION, preview: true });
91
+ expect(manifestRoute.prerender).toBe(true);
92
+ });
93
+
94
+ it("carries the version package.json carries, so a release names one thing", () => {
95
+ const pkg = JSON.parse(readFileSync(resolve(__dirname, "../../package.json"), "utf8"));
96
+ expect(THEME_VERSION).toBe(pkg.version);
97
+ });
98
+ });
99
+
100
+ describe("the preview Studio frames", () => {
101
+ it("opens for a pass Studio signed for this store and theme", async () => {
102
+ const { next, preview } = await openPreview(await sign(previewPass()));
103
+ expect(next).toHaveBeenCalledWith();
104
+ expect(preview?.claims.editor).toBe(EDITOR);
105
+ expect(preview?.draft.surface).toBe("home");
106
+ });
107
+
108
+ it("refuses a pass for another theme, a revalidation token, or none", async () => {
109
+ for (const token of [await sign(previewPass({ theme: "another-theme" })), await sign(revalidation()), undefined]) {
110
+ const { response, next, preview } = await openPreview(token);
111
+ expect(response.status).toBeGreaterThanOrEqual(400);
112
+ expect(next).not.toHaveBeenCalled();
113
+ expect(preview).toBeUndefined();
114
+ }
115
+ });
116
+
117
+ it("renders the draft with every section marked and the editor's bridge, never cached", async () => {
118
+ const token = await sign(previewPass());
119
+ const { preview } = await openPreview(token);
120
+ if (!preview) throw new Error("the pass was refused");
121
+ const container = await AstroContainer.create();
122
+ const response = await container.renderToResponse(PreviewPage, {
123
+ request: previewRequest(token),
124
+ locals: { store: storeContext("ar"), preview } as unknown as App.Locals,
125
+ });
126
+ const html = await response.text();
127
+ expect(response.status).toBe(200);
128
+ expect(response.headers.get("Cache-Control")).toMatch(/no-store/);
129
+ expect(html.match(/<!--abcart:start id=/g)?.length ?? 0).toBeGreaterThan(3);
130
+ expect(html).toContain(EDITOR);
131
+ });
132
+
133
+ it("is a 404 on a deployment without the key", async () => {
134
+ const { response, preview } = await withoutKey(async () => openPreview(await sign(previewPass())));
135
+ expect(response.status).toBe(404);
136
+ expect(preview).toBeUndefined();
137
+ });
138
+ });
139
+
140
+ describe("the revalidation a publish sends", () => {
141
+ it("drops every cached page for the platform's revalidation token", async () => {
142
+ const { response, invalidate } = await publish(`Bearer ${await sign(revalidation())}`);
143
+ expect(response.status).toBe(204);
144
+ expect(response.headers.get("Cache-Control")).toBe("no-store");
145
+ expect(invalidate).toHaveBeenCalledWith({ tags: ["pages"] });
146
+ });
147
+
148
+ it("drops nothing for a preview pass, another store's or theme's token, or none", async () => {
149
+ for (const token of [await sign(previewPass()), await sign(revalidation({ aud: "https://other.test" })), await sign(revalidation({ theme: "another-theme" }))]) {
150
+ const { response, invalidate } = await publish(`Bearer ${token}`);
151
+ expect(response.status).toBe(403);
152
+ expect(invalidate).not.toHaveBeenCalled();
153
+ }
154
+ const { response, invalidate } = await publish();
155
+ expect(response.status).toBe(401);
156
+ expect(invalidate).not.toHaveBeenCalled();
157
+ });
158
+
159
+ it("is a 404 on a deployment without the key", async () => {
160
+ const { response, invalidate } = await withoutKey(async () => publish(`Bearer ${await sign(revalidation())}`));
161
+ expect(response.status).toBe(404);
162
+ expect(invalidate).not.toHaveBeenCalled();
163
+ });
164
+
165
+ it("answers only POST, and is never prerendered", async () => {
166
+ const response = (revalidate.ALL as () => Response)();
167
+ expect(response.status).toBe(405);
168
+ expect(revalidate.prerender).toBe(false);
169
+ });
170
+
171
+ it("reaches every cached page: each page route rule carries the SDK's pages tag, never its spelling", () => {
172
+ const config = readFileSync(resolve(__dirname, "../../astro.config.mjs"), "utf8");
173
+ const rules = config.slice(config.indexOf("routeRules: {"), config.indexOf("\n },", config.indexOf("routeRules: {")));
174
+ const routes = [...rules.matchAll(/"([^"]+)":\s*\{[^}]*tags:\s*\[([^\]]*)\]/g)].map((match) => ({ route: match[1]!, tags: match[2]! }));
175
+ expect(routes.length).toBeGreaterThan(5);
176
+ expect(routes.filter((rule) => !rule.route.startsWith("/api/") && !rule.tags.includes("PAGES_CACHE_TAG")).map((rule) => rule.route)).toEqual([]);
177
+ expect(rules).not.toContain('"pages"');
178
+ expect(config).toMatch(/import \{ PAGES_CACHE_TAG \} from "@abcart\/storefront\/server";/);
179
+ });
180
+ });
181
+
182
+ describe("what a publish reaches", () => {
183
+ /** Routes a shopper's own request decides — a search, a basket, an order — and the contact page the siblings leave uncached too. */
184
+ const UNCACHED = ["/search", "/checkout", "/thank-you", "/track-order", "/contact"];
185
+ const config = readFileSync(resolve(__dirname, "../../astro.config.mjs"), "utf8");
186
+ const rules = new Map([...config.matchAll(/"(\/[^"]*)":\s*\{[^}]*tags:\s*\[([^\]]*)\]/g)].map((match) => [match[1]!, match[2]!]));
187
+ const pagesDir = resolve(__dirname, "../../src/pages");
188
+ const walk = (dir: string): string[] => readdirSync(dir, { withFileTypes: true }).flatMap((entry) => (entry.isDirectory() ? walk(join(dir, entry.name)) : [join(dir, entry.name)]));
189
+ /** Every route that renders a composed surface, as routeRules names it. */
190
+ const composed = walk(pagesDir)
191
+ .filter((file) => file.endsWith(".astro") && !file.endsWith("abcart-preview.astro") && readFileSync(file, "utf8").includes("<Sections"))
192
+ .map((file) => `/${relative(pagesDir, file).split(sep).join("/").replace(/\.astro$/, "").replace(/(^|\/)index$/, "")}`);
193
+
194
+ it("finds the composed routes, so the check means something", () => {
195
+ expect(composed.length).toBeGreaterThanOrEqual(12);
196
+ });
197
+
198
+ it("caches every composed route under the pages tag, unless a shopper's own request decides the page", () => {
199
+ expect(composed.filter((route) => !UNCACHED.includes(route) && !rules.get(route)?.includes("PAGES_CACHE_TAG"))).toEqual([]);
200
+ expect(UNCACHED.filter((route) => !composed.includes(route) || rules.has(route))).toEqual([]);
201
+ });
202
+ });
@@ -1,52 +1,52 @@
1
- /**
2
- * The testimonials section shows what shoppers wrote — real reviews read
3
- * through the SDK, never words a merchant types in — and is not there when
4
- * the store has none or turned reviews off.
5
- */
6
- import { describe, expect, it } from "vitest";
7
- import { experimental_AstroContainer as AstroContainer } from "astro/container";
8
- import type { Review } from "@abcart/storefront";
9
- import type { StoreClient } from "@abcart/storefront/server";
10
- import { createReadCache } from "@abcart/theme/astro";
11
- import Sections from "../../src/components/surface/Sections.astro";
12
- import { storeContext, storeDouble } from "./fixtures";
13
-
14
- const review = (id: string, rating: number, body: string, createdAt: string): Review => ({ id, customerName: `زبون ${id}`, rating, title: null, body, createdAt, verified: true, media: [] });
15
- const ROWS = [
16
- review("r1", 5, "قماش ناعم ومقاس مضبوط.", "2026-10-20T10:00:00.000Z"),
17
- review("r2", 3, "مقبول.", "2026-10-22T10:00:00.000Z"),
18
- review("r3", 4, "وصلت بسرعة.", "2026-10-25T10:00:00.000Z"),
19
- ];
20
-
21
- function client(rows: Review[]): StoreClient {
22
- const double = storeDouble();
23
- return { ...double, products: { ...double.products, reviews: { list: async () => ({ rows, total: rows.length }) } } } as unknown as StoreClient;
24
- }
25
-
26
- async function render(rows: Review[], options: { reviewsEnabled?: boolean; props?: Record<string, unknown> } = {}) {
27
- const container = await AstroContainer.create();
28
- const document = { version: 1, surface: "home", sections: [{ id: "t", type: "testimonials", props: options.props ?? {} }] };
29
- return container.renderToString(Sections, {
30
- props: { surface: "home", document, params: {}, reads: createReadCache(), preview: false },
31
- locals: { store: storeContext("ar", client(rows), { reviewsEnabled: options.reviewsEnabled ?? true }) } as unknown as App.Locals,
32
- });
33
- }
34
-
35
- describe("the testimonials section", () => {
36
- it("shows the store's reviews at or above the lowest rating, newest first, each linking its product", async () => {
37
- const html = await render(ROWS);
38
- expect(html.indexOf("وصلت بسرعة.")).toBeGreaterThan(0);
39
- expect(html.indexOf("وصلت بسرعة.")).toBeLessThan(html.indexOf("قماش ناعم ومقاس مضبوط."));
40
- expect(html).not.toContain("مقبول.");
41
- expect(html).toMatch(/class="testimonial__product" href="\/products\/linen-shirt"/);
42
- });
43
-
44
- it("lets the merchant show lower ratings too", async () => {
45
- expect(await render(ROWS, { props: { minRating: 3 } })).toContain("مقبول.");
46
- });
47
-
48
- it("is not there without reviews, or with reviews turned off", async () => {
49
- expect(await render([])).not.toContain("testimonial");
50
- expect(await render(ROWS, { reviewsEnabled: false })).not.toContain("testimonial");
51
- });
52
- });
1
+ /**
2
+ * The testimonials section shows what shoppers wrote — real reviews read
3
+ * through the SDK, never words a merchant types in — and is not there when
4
+ * the store has none or turned reviews off.
5
+ */
6
+ import { describe, expect, it } from "vitest";
7
+ import { experimental_AstroContainer as AstroContainer } from "astro/container";
8
+ import type { Review } from "@abcart/storefront";
9
+ import type { StoreClient } from "@abcart/storefront/server";
10
+ import { createReadCache } from "@abcart/theme/astro";
11
+ import Sections from "../../src/components/surface/Sections.astro";
12
+ import { storeContext, storeDouble } from "./fixtures";
13
+
14
+ const review = (id: string, rating: number, body: string, createdAt: string): Review => ({ id, customerName: `زبون ${id}`, rating, title: null, body, createdAt, verified: true, media: [] });
15
+ const ROWS = [
16
+ review("r1", 5, "قماش ناعم ومقاس مضبوط.", "2026-10-20T10:00:00.000Z"),
17
+ review("r2", 3, "مقبول.", "2026-10-22T10:00:00.000Z"),
18
+ review("r3", 4, "وصلت بسرعة.", "2026-10-25T10:00:00.000Z"),
19
+ ];
20
+
21
+ function client(rows: Review[]): StoreClient {
22
+ const double = storeDouble();
23
+ return { ...double, products: { ...double.products, reviews: { list: async () => ({ rows, total: rows.length }) } } } as unknown as StoreClient;
24
+ }
25
+
26
+ async function render(rows: Review[], options: { reviewsEnabled?: boolean; props?: Record<string, unknown> } = {}) {
27
+ const container = await AstroContainer.create();
28
+ const document = { version: 1, surface: "home", sections: [{ id: "t", type: "testimonials", props: options.props ?? {} }] };
29
+ return container.renderToString(Sections, {
30
+ props: { surface: "home", document, params: {}, reads: createReadCache(), preview: false },
31
+ locals: { store: storeContext("ar", client(rows), { reviewsEnabled: options.reviewsEnabled ?? true }) } as unknown as App.Locals,
32
+ });
33
+ }
34
+
35
+ describe("the testimonials section", () => {
36
+ it("shows the store's reviews at or above the lowest rating, newest first, each linking its product", async () => {
37
+ const html = await render(ROWS);
38
+ expect(html.indexOf("وصلت بسرعة.")).toBeGreaterThan(0);
39
+ expect(html.indexOf("وصلت بسرعة.")).toBeLessThan(html.indexOf("قماش ناعم ومقاس مضبوط."));
40
+ expect(html).not.toContain("مقبول.");
41
+ expect(html).toMatch(/class="testimonial__product" href="\/products\/linen-shirt"/);
42
+ });
43
+
44
+ it("lets the merchant show lower ratings too", async () => {
45
+ expect(await render(ROWS, { props: { minRating: 3 } })).toContain("مقبول.");
46
+ });
47
+
48
+ it("is not there without reviews, or with reviews turned off", async () => {
49
+ expect(await render([])).not.toContain("testimonial");
50
+ expect(await render(ROWS, { reviewsEnabled: false })).not.toContain("testimonial");
51
+ });
52
+ });
@@ -1,52 +1,52 @@
1
- /**
2
- * The thank-you page is a surface the merchant edits like any other: the
3
- * order's confirmation shows the order the link names, in the merchant's
4
- * words, with the ways on they keep, and other sections can follow it.
5
- */
6
- import { describe, expect, it } from "vitest";
7
- import { experimental_AstroContainer as AstroContainer } from "astro/container";
8
- import { createReadCache } from "@abcart/theme/astro";
9
- import Sections from "../../src/components/surface/Sections.astro";
10
- import { ORDER_EXAMPLE } from "../../src/lib/order-outcome";
11
- import { content } from "../../src/theme/content";
12
- import { storeContext } from "./fixtures";
13
-
14
- async function render(document: unknown, params: Record<string, string>, preview = false) {
15
- const container = await AstroContainer.create();
16
- return container.renderToString(Sections, {
17
- props: { surface: "thank-you", document, params, reads: createReadCache(), preview },
18
- locals: { store: storeContext("ar") } as unknown as App.Locals,
19
- });
20
- }
21
-
22
- const page = (props: Record<string, unknown>, more: unknown[] = []) => ({
23
- version: 1,
24
- surface: "thank-you",
25
- sections: [{ id: "thank-you-main", type: "thank-you-main", props }, ...more],
26
- });
27
-
28
- describe("the thank-you page", () => {
29
- it("confirms the order its link names, with the theme's words until the merchant edits them", async () => {
30
- const html = await render(null, { orderNumber: "ORD-20261031-0007", total: "4800" });
31
- expect(html).toContain("ORD-20261031-0007");
32
- expect(html).toContain("4.800");
33
- expect(html).toContain(content.ar["thankYou.title"]);
34
- expect(html).toMatch(/href="\/track-order\?order=ORD-20261031-0007"/);
35
- });
36
-
37
- it("says what the merchant wrote, and shows only the ways on they keep", async () => {
38
- const html = await render(page({ title: { ar: "وصلنا طلبك يا غالي" }, showTrack: false, showContinue: false }), { orderNumber: "ORD-20261031-0007", total: "" });
39
- expect(html).toContain("وصلنا طلبك يا غالي");
40
- expect(html).not.toContain("/track-order");
41
- expect(html).not.toContain(content.ar["thankYou.continue"]);
42
- });
43
-
44
- it("takes other sections after the confirmation", async () => {
45
- const html = await render(page({}, [{ id: "note", type: "rich-text", props: { title: { ar: "هدية مع طلبك القادم" } } }]), { orderNumber: "ORD-20261031-0007", total: "" });
46
- expect(html.indexOf("ORD-20261031-0007")).toBeLessThan(html.indexOf("هدية مع طلبك القادم"));
47
- });
48
-
49
- it("shows an example order in the editor's preview, where none was placed", async () => {
50
- expect(await render(null, {}, true)).toContain(ORDER_EXAMPLE);
51
- });
52
- });
1
+ /**
2
+ * The thank-you page is a surface the merchant edits like any other: the
3
+ * order's confirmation shows the order the link names, in the merchant's
4
+ * words, with the ways on they keep, and other sections can follow it.
5
+ */
6
+ import { describe, expect, it } from "vitest";
7
+ import { experimental_AstroContainer as AstroContainer } from "astro/container";
8
+ import { createReadCache } from "@abcart/theme/astro";
9
+ import Sections from "../../src/components/surface/Sections.astro";
10
+ import { ORDER_EXAMPLE } from "../../src/lib/order-outcome";
11
+ import { content } from "../../src/theme/content";
12
+ import { storeContext } from "./fixtures";
13
+
14
+ async function render(document: unknown, params: Record<string, string>, preview = false) {
15
+ const container = await AstroContainer.create();
16
+ return container.renderToString(Sections, {
17
+ props: { surface: "thank-you", document, params, reads: createReadCache(), preview },
18
+ locals: { store: storeContext("ar") } as unknown as App.Locals,
19
+ });
20
+ }
21
+
22
+ const page = (props: Record<string, unknown>, more: unknown[] = []) => ({
23
+ version: 1,
24
+ surface: "thank-you",
25
+ sections: [{ id: "thank-you-main", type: "thank-you-main", props }, ...more],
26
+ });
27
+
28
+ describe("the thank-you page", () => {
29
+ it("confirms the order its link names, with the theme's words until the merchant edits them", async () => {
30
+ const html = await render(null, { orderNumber: "ORD-20261031-0007", total: "4800" });
31
+ expect(html).toContain("ORD-20261031-0007");
32
+ expect(html).toContain("4.800");
33
+ expect(html).toContain(content.ar["thankYou.title"]);
34
+ expect(html).toMatch(/href="\/track-order\?order=ORD-20261031-0007"/);
35
+ });
36
+
37
+ it("says what the merchant wrote, and shows only the ways on they keep", async () => {
38
+ const html = await render(page({ title: { ar: "وصلنا طلبك يا غالي" }, showTrack: false, showContinue: false }), { orderNumber: "ORD-20261031-0007", total: "" });
39
+ expect(html).toContain("وصلنا طلبك يا غالي");
40
+ expect(html).not.toContain("/track-order");
41
+ expect(html).not.toContain(content.ar["thankYou.continue"]);
42
+ });
43
+
44
+ it("takes other sections after the confirmation", async () => {
45
+ const html = await render(page({}, [{ id: "note", type: "rich-text", props: { title: { ar: "هدية مع طلبك القادم" } } }]), { orderNumber: "ORD-20261031-0007", total: "" });
46
+ expect(html.indexOf("ORD-20261031-0007")).toBeLessThan(html.indexOf("هدية مع طلبك القادم"));
47
+ });
48
+
49
+ it("shows an example order in the editor's preview, where none was placed", async () => {
50
+ expect(await render(null, {}, true)).toContain(ORDER_EXAMPLE);
51
+ });
52
+ });