@jarwizz/create-jarshop 0.1.9 → 0.3.1
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.
- package/README.md +15 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/generator.d.ts +11 -1
- package/dist/generator.js +45 -11
- package/dist/generator.js.map +1 -1
- package/dist/presets.d.ts +26 -0
- package/dist/presets.js +94 -0
- package/dist/presets.js.map +1 -0
- package/dist/template/CONTEXT.md +4 -2
- package/dist/template/README.md +255 -3
- package/dist/template/env.example.template +19 -0
- package/dist/template/gitignore.template +1 -0
- package/dist/template/jarshop.config.ts +31 -0
- package/dist/template/package.json +4 -0
- package/dist/template/pnpm-lock.yaml +3284 -1815
- package/dist/template/pnpm-workspace.yaml +6 -1
- package/dist/template/src/client/features.ts +41 -0
- package/dist/template/src/client/invoicing.ts +29 -0
- package/dist/template/src/dev-storefront-environment.test.ts +45 -0
- package/dist/template/src/dev-storefront-environment.ts +32 -0
- package/dist/template/src/dev-storefront.ts +3 -12
- package/dist/template/src/environment.d.ts +8 -0
- package/dist/template/src/invoice-email-recover.ts +59 -0
- package/dist/template/src/jarshop-config-loader.ts +118 -0
- package/dist/template/src/jarshop-config.test.ts +335 -0
- package/dist/template/src/jarshop-config.ts +439 -0
- package/dist/template/src/jarshop-features.test.ts +222 -0
- package/dist/template/src/jarshop-features.ts +112 -0
- package/dist/template/src/operation-codes.ts +34 -0
- package/dist/template/src/packeta-config.test.ts +95 -0
- package/dist/template/src/packeta-countries.test.ts +161 -0
- package/dist/template/src/packeta-countries.ts +120 -0
- package/dist/template/src/packeta-validation.test.ts +35 -0
- package/dist/template/src/packeta-validation.ts +52 -0
- package/dist/template/src/payment-return-url.test.ts +57 -0
- package/dist/template/src/payment-return-url.ts +34 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation-view.test.ts +79 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation.ts +51 -0
- package/dist/template/src/plugins/jarshop-checkout/dashboard/index.tsx +1 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-delivery.plugin.ts +79 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-events.ts +35 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-lifecycle.ts +235 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-worker.test.ts +426 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email.test.ts +107 -0
- package/dist/template/src/plugins/jarshop-checkout/jarshop-checkout.plugin.ts +161 -57
- package/dist/template/src/plugins/jarshop-checkout/market-channels.test.ts +58 -0
- package/dist/template/src/plugins/jarshop-checkout/market-channels.ts +87 -0
- package/dist/template/src/plugins/jarshop-checkout/operation-code-check.ts +36 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.entity.ts +1 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.ts +1 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-core.ts +94 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery.entity.ts +1 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-outbox.ts +83 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-worker.ts +136 -1
- package/dist/template/src/plugins/jarshop-checkout/shipping-tax.test.ts +109 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping.test.ts +156 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping.ts +75 -11
- package/dist/template/src/seed.ts +427 -184
- package/dist/template/src/vendure-config.ts +258 -113
- package/dist/template/storefront/README.md +7 -0
- package/dist/template/storefront/app/[locale]/[slug]/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/login/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/page.tsx +10 -4
- package/dist/template/storefront/app/[locale]/account/password-reset/callback/route.ts +4 -2
- package/dist/template/storefront/app/[locale]/account/password-reset/complete/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/password-reset/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/register/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/verify/complete/route.ts +4 -2
- package/dist/template/storefront/app/[locale]/account/verify/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/cart/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/checkout/actions.ts +43 -0
- package/dist/template/storefront/app/[locale]/checkout/checkout-form.tsx +188 -36
- package/dist/template/storefront/app/[locale]/checkout/confirmation/route.ts +2 -2
- package/dist/template/storefront/app/[locale]/checkout/packeta-chooser.tsx +96 -0
- package/dist/template/storefront/app/[locale]/checkout/page.tsx +60 -2
- package/dist/template/storefront/app/[locale]/checkout/payment-return/actions.ts +55 -0
- package/dist/template/storefront/app/[locale]/checkout/payment-return/page.tsx +32 -0
- package/dist/template/storefront/app/[locale]/checkout/payment-return/payment-return.tsx +84 -0
- package/dist/template/storefront/app/[locale]/checkout/success/page.tsx +32 -2
- package/dist/template/storefront/app/[locale]/layout.tsx +3 -2
- package/dist/template/storefront/app/[locale]/page.tsx +3 -2
- package/dist/template/storefront/app/globals.css +16 -0
- package/dist/template/storefront/app/layout.tsx +6 -2
- package/dist/template/storefront/lib/cart.ts +2 -4
- package/dist/template/storefront/lib/checkout-contract.test.ts +18 -1
- package/dist/template/storefront/lib/checkout-contract.ts +8 -0
- package/dist/template/storefront/lib/checkout-countries.test.ts +61 -0
- package/dist/template/storefront/lib/checkout-countries.ts +67 -0
- package/dist/template/storefront/lib/checkout.ts +22 -11
- package/dist/template/storefront/lib/commerce.ts +262 -2
- package/dist/template/storefront/lib/confirmation.test.ts +116 -0
- package/dist/template/storefront/lib/confirmation.ts +13 -7
- package/dist/template/storefront/lib/i18n.test.ts +32 -12
- package/dist/template/storefront/lib/i18n.ts +29 -8
- package/dist/template/storefront/lib/market-config.ts +40 -0
- package/dist/template/storefront/lib/market-routing.test.ts +107 -0
- package/dist/template/storefront/lib/market-routing.ts +57 -0
- package/dist/template/storefront/lib/market.ts +51 -0
- package/dist/template/storefront/lib/packeta-selection.test.ts +141 -0
- package/dist/template/storefront/lib/packeta-selection.ts +98 -0
- package/dist/template/storefront/lib/payment-return-actions.test.ts +61 -0
- package/dist/template/storefront/lib/payment-return-page.test.ts +30 -0
- package/dist/template/storefront/lib/payment-return-polling.test.ts +37 -0
- package/dist/template/storefront/lib/payment-return-polling.ts +58 -0
- package/dist/template/storefront/messages/en.json +13 -1
- package/dist/template/storefront/messages/sk.json +13 -1
- package/dist/template/storefront/package.json +2 -1
- package/dist/template/storefront/proxy.ts +35 -0
- package/dist/template/turbo.json +5 -1
- package/dist/template-manifest.json +1 -1
- package/dist/template.js +1 -0
- package/dist/template.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
JarShopConfigError,
|
|
8
|
+
configuredLanguages,
|
|
9
|
+
marketForChannelToken,
|
|
10
|
+
marketServesCountry,
|
|
11
|
+
normalizeHost,
|
|
12
|
+
parseJarShopConfig,
|
|
13
|
+
resolveMarketForHost,
|
|
14
|
+
resolveMarketLanguage,
|
|
15
|
+
routeMarketPath,
|
|
16
|
+
supportedCurrencyCodes,
|
|
17
|
+
supportedLanguageCodes,
|
|
18
|
+
type JarShopMarket,
|
|
19
|
+
} from "./jarshop-config.js";
|
|
20
|
+
import { CurrencyCode, LanguageCode } from "@vendure/core";
|
|
21
|
+
import {
|
|
22
|
+
locateJarShopConfig,
|
|
23
|
+
readJarShopConfig,
|
|
24
|
+
storefrontMarketUrl,
|
|
25
|
+
storefrontOriginForMarket,
|
|
26
|
+
} from "./jarshop-config-loader.js";
|
|
27
|
+
|
|
28
|
+
const slovakia = {
|
|
29
|
+
code: "sk",
|
|
30
|
+
channelToken: "sk",
|
|
31
|
+
defaultLanguage: "sk",
|
|
32
|
+
languages: ["sk", "en"],
|
|
33
|
+
currency: "EUR",
|
|
34
|
+
countries: ["SK"],
|
|
35
|
+
domains: ["shop.example.sk"],
|
|
36
|
+
};
|
|
37
|
+
const czechia = {
|
|
38
|
+
code: "cz",
|
|
39
|
+
channelToken: "cz",
|
|
40
|
+
defaultLanguage: "cs",
|
|
41
|
+
languages: ["cs", "en"],
|
|
42
|
+
currency: "CZK",
|
|
43
|
+
countries: ["CZ"],
|
|
44
|
+
domains: ["shop.example.cz", "www.shop.example.cz"],
|
|
45
|
+
};
|
|
46
|
+
const multiMarket = { defaultMarket: "sk", markets: [slovakia, czechia] };
|
|
47
|
+
|
|
48
|
+
function issuesOf(value: unknown): readonly string[] {
|
|
49
|
+
try {
|
|
50
|
+
parseJarShopConfig(value);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
expect(error).toBeInstanceOf(JarShopConfigError);
|
|
53
|
+
return (error as JarShopConfigError).issues;
|
|
54
|
+
}
|
|
55
|
+
throw new Error("configuration was accepted");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const temporaryDirectories: string[] = [];
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
for (const directory of temporaryDirectories.splice(0)) {
|
|
61
|
+
rmSync(directory, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("jarshop.config.ts validation", () => {
|
|
66
|
+
it("accepts a single market without domains and a multi-market config", () => {
|
|
67
|
+
expect(
|
|
68
|
+
parseJarShopConfig({
|
|
69
|
+
defaultMarket: "sk",
|
|
70
|
+
markets: [{ ...slovakia, domains: [] }],
|
|
71
|
+
}).markets,
|
|
72
|
+
).toHaveLength(1);
|
|
73
|
+
expect(parseJarShopConfig(multiMarket).markets.map((m) => m.code)).toEqual([
|
|
74
|
+
"sk",
|
|
75
|
+
"cz",
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("rejects an unknown or lower-case currency", () => {
|
|
80
|
+
expect(
|
|
81
|
+
issuesOf({
|
|
82
|
+
...multiMarket,
|
|
83
|
+
markets: [{ ...slovakia, currency: "EURO" }],
|
|
84
|
+
}),
|
|
85
|
+
).toEqual([
|
|
86
|
+
'market "sk" currency "EURO" is not a supported upper-case ISO 4217 code',
|
|
87
|
+
]);
|
|
88
|
+
expect(
|
|
89
|
+
issuesOf({ ...multiMarket, markets: [{ ...slovakia, currency: "eur" }] }),
|
|
90
|
+
).toHaveLength(1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("rejects a language Vendure does not know", () => {
|
|
94
|
+
expect(
|
|
95
|
+
issuesOf({
|
|
96
|
+
defaultMarket: "sk",
|
|
97
|
+
markets: [{ ...slovakia, languages: ["sk", "xx"] }],
|
|
98
|
+
}),
|
|
99
|
+
).toEqual([
|
|
100
|
+
'market "sk" language "xx" must be a lower-case ISO 639-1 code that Vendure supports',
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("accepts exactly Vendure's two-letter languages and its currencies", () => {
|
|
105
|
+
const vendureLanguages = Object.values(LanguageCode).filter((code) =>
|
|
106
|
+
/^[a-z]{2}$/u.test(code),
|
|
107
|
+
);
|
|
108
|
+
expect([...supportedLanguageCodes].sort()).toEqual(
|
|
109
|
+
[...vendureLanguages].sort(),
|
|
110
|
+
);
|
|
111
|
+
expect([...supportedCurrencyCodes].sort()).toEqual(
|
|
112
|
+
[...Object.values(CurrencyCode)].sort(),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("rejects a country that is not an ISO 3166-1 alpha-2 code", () => {
|
|
117
|
+
expect(
|
|
118
|
+
issuesOf({
|
|
119
|
+
...multiMarket,
|
|
120
|
+
markets: [{ ...slovakia, countries: ["SK", "XX", "cz"] }],
|
|
121
|
+
}),
|
|
122
|
+
).toEqual([
|
|
123
|
+
'market "sk" country "XX" is not an upper-case ISO 3166-1 alpha-2 code',
|
|
124
|
+
'market "sk" country "cz" is not an upper-case ISO 3166-1 alpha-2 code',
|
|
125
|
+
]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("rejects a domain claimed by two markets", () => {
|
|
129
|
+
expect(
|
|
130
|
+
issuesOf({
|
|
131
|
+
...multiMarket,
|
|
132
|
+
markets: [slovakia, { ...czechia, domains: ["shop.example.sk"] }],
|
|
133
|
+
}),
|
|
134
|
+
).toEqual([
|
|
135
|
+
'domain "shop.example.sk" is declared by both market "sk" and market "cz"',
|
|
136
|
+
]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("rejects an unknown default market", () => {
|
|
140
|
+
expect(issuesOf({ ...multiMarket, defaultMarket: "de" })).toEqual([
|
|
141
|
+
'defaultMarket "de" must name one of the markets (sk, cz)',
|
|
142
|
+
]);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("reports every problem of a broken market at once", () => {
|
|
146
|
+
const issues = issuesOf({
|
|
147
|
+
defaultMarket: "sk",
|
|
148
|
+
markets: [
|
|
149
|
+
slovakia,
|
|
150
|
+
{
|
|
151
|
+
...czechia,
|
|
152
|
+
code: "SK",
|
|
153
|
+
channelToken: "sk",
|
|
154
|
+
defaultLanguage: "de",
|
|
155
|
+
languages: ["cs", "cs"],
|
|
156
|
+
domains: ["https://shop.example.cz"],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
});
|
|
160
|
+
expect(issues).toEqual(
|
|
161
|
+
expect.arrayContaining([
|
|
162
|
+
'markets[1].code must be a lower-case identifier such as "sk" (got "SK")',
|
|
163
|
+
'market "SK" reuses channelToken "sk"; every market needs its own Vendure Channel',
|
|
164
|
+
'market "SK" languages contains duplicate "cs"',
|
|
165
|
+
'market "SK" defaultLanguage "de" must be one of its languages',
|
|
166
|
+
'market "SK" domain "https://shop.example.cz" must be a lower-case host name without scheme, port or path',
|
|
167
|
+
]),
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("requires a domain for every market once there are several", () => {
|
|
172
|
+
expect(
|
|
173
|
+
issuesOf({
|
|
174
|
+
...multiMarket,
|
|
175
|
+
markets: [slovakia, { ...czechia, domains: [] }],
|
|
176
|
+
}),
|
|
177
|
+
).toEqual([
|
|
178
|
+
'market "cz" needs at least one domain when a project has several markets',
|
|
179
|
+
]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("rejects a missing or empty market list with a readable message", () => {
|
|
183
|
+
expect(() => parseJarShopConfig(undefined)).toThrow(
|
|
184
|
+
"the default export must be an object",
|
|
185
|
+
);
|
|
186
|
+
expect(() => parseJarShopConfig({ defaultMarket: "sk" })).toThrow(
|
|
187
|
+
"markets must be a non-empty array",
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe("market resolution", () => {
|
|
193
|
+
const config = parseJarShopConfig(multiMarket);
|
|
194
|
+
|
|
195
|
+
it("selects the market whose domain matches the request host", () => {
|
|
196
|
+
expect(resolveMarketForHost(config, "shop.example.cz")?.code).toBe("cz");
|
|
197
|
+
expect(resolveMarketForHost(config, "WWW.Shop.Example.CZ:443")?.code).toBe(
|
|
198
|
+
"cz",
|
|
199
|
+
);
|
|
200
|
+
expect(
|
|
201
|
+
resolveMarketForHost(config, "shop.example.sk., proxy.internal")?.code,
|
|
202
|
+
).toBe("sk");
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("falls back to the development market and then the default market", () => {
|
|
206
|
+
expect(resolveMarketForHost(config, "localhost:3001")?.code).toBe("sk");
|
|
207
|
+
expect(
|
|
208
|
+
resolveMarketForHost(config, "localhost:3001", { fallbackMarket: "cz" })
|
|
209
|
+
?.code,
|
|
210
|
+
).toBe("cz");
|
|
211
|
+
// A matching domain always wins over the development fallback.
|
|
212
|
+
expect(
|
|
213
|
+
resolveMarketForHost(config, "shop.example.sk", { fallbackMarket: "cz" })
|
|
214
|
+
?.code,
|
|
215
|
+
).toBe("sk");
|
|
216
|
+
expect(() =>
|
|
217
|
+
resolveMarketForHost(config, "localhost", { fallbackMarket: "hu" }),
|
|
218
|
+
).toThrow('JARSHOP_DEV_MARKET "hu" is not a market');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("serves no market on an unknown production host of a multi-market project", () => {
|
|
222
|
+
const production = { production: true, fallbackMarket: "cz" } as const;
|
|
223
|
+
expect(resolveMarketForHost(config, "unknown.example", production)).toBe(
|
|
224
|
+
undefined,
|
|
225
|
+
);
|
|
226
|
+
expect(
|
|
227
|
+
resolveMarketForHost(config, "shop.example.cz", production)?.code,
|
|
228
|
+
).toBe("cz");
|
|
229
|
+
const single = parseJarShopConfig({
|
|
230
|
+
defaultMarket: "sk",
|
|
231
|
+
markets: [{ ...slovakia, domains: [] }],
|
|
232
|
+
});
|
|
233
|
+
expect(resolveMarketForHost(single, "10.0.0.5", production)?.code).toBe(
|
|
234
|
+
"sk",
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("redirects a path language the market does not serve and 404s a non-language", () => {
|
|
239
|
+
const czech = resolveMarketForHost(config, "shop.example.cz")!;
|
|
240
|
+
expect(routeMarketPath(czech, "/cs/cart")).toEqual({ kind: "serve" });
|
|
241
|
+
expect(routeMarketPath(czech, "/en/cart")).toEqual({ kind: "serve" });
|
|
242
|
+
expect(routeMarketPath(czech, "/sk/cart")).toEqual({
|
|
243
|
+
kind: "redirect",
|
|
244
|
+
pathname: "/cs/cart",
|
|
245
|
+
});
|
|
246
|
+
expect(routeMarketPath(czech, "/EN-gb")).toEqual({
|
|
247
|
+
kind: "redirect",
|
|
248
|
+
pathname: "/en",
|
|
249
|
+
});
|
|
250
|
+
expect(routeMarketPath(czech, "/")).toEqual({
|
|
251
|
+
kind: "redirect",
|
|
252
|
+
pathname: "/cs",
|
|
253
|
+
});
|
|
254
|
+
expect(routeMarketPath(czech, "/xx/cart")).toEqual({ kind: "not-found" });
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("normalizes host header values", () => {
|
|
258
|
+
expect(normalizeHost(" Shop.Example.SK:3000 ")).toBe("shop.example.sk");
|
|
259
|
+
expect(normalizeHost("[::1]:3001")).toBe("[::1]");
|
|
260
|
+
expect(normalizeHost(undefined)).toBe("");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("restricts the path language to the market's languages", () => {
|
|
264
|
+
const czech = resolveMarketForHost(config, "shop.example.cz")!;
|
|
265
|
+
expect(resolveMarketLanguage(czech, "cs")).toBe("cs");
|
|
266
|
+
expect(resolveMarketLanguage(czech, "en-GB")).toBe("en");
|
|
267
|
+
expect(resolveMarketLanguage(czech, "sk")).toBe("cs");
|
|
268
|
+
expect(resolveMarketLanguage(czech, undefined)).toBe("cs");
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("finds a market by channel token and courier country", () => {
|
|
272
|
+
const czech = marketForChannelToken(config, "cz") as JarShopMarket;
|
|
273
|
+
expect(czech.code).toBe("cz");
|
|
274
|
+
expect(marketForChannelToken(config, "unknown")).toBeUndefined();
|
|
275
|
+
expect(marketServesCountry(czech, "CZ")).toBe(true);
|
|
276
|
+
expect(marketServesCountry(czech, "SK")).toBe(false);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("lists the default market's languages first", () => {
|
|
280
|
+
expect(configuredLanguages(config)).toEqual(["sk", "en", "cs"]);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe("server configuration loading", () => {
|
|
285
|
+
it("loads and validates the project's own jarshop.config.ts", () => {
|
|
286
|
+
const file = locateJarShopConfig(__dirname);
|
|
287
|
+
expect(path.basename(file)).toBe("jarshop.config.ts");
|
|
288
|
+
expect(readJarShopConfig(file).markets.length).toBeGreaterThan(0);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("names the file and every problem when the configuration is invalid", () => {
|
|
292
|
+
const directory = mkdtempSync(path.join(tmpdir(), "jarshop-config-"));
|
|
293
|
+
temporaryDirectories.push(directory);
|
|
294
|
+
const file = path.join(directory, "jarshop.config.ts");
|
|
295
|
+
writeFileSync(
|
|
296
|
+
file,
|
|
297
|
+
`export default { defaultMarket: "cz", markets: [{ code: "sk", channelToken: "sk", defaultLanguage: "sk", languages: ["sk"], currency: "SKK", countries: ["SK"], domains: [] }] } as const;\n`,
|
|
298
|
+
);
|
|
299
|
+
expect(locateJarShopConfig(path.join(directory))).toBe(file);
|
|
300
|
+
expect(() => readJarShopConfig(file)).toThrow(
|
|
301
|
+
`Invalid ${file}:\n - market "sk" currency "SKK" is not a supported upper-case ISO 4217 code\n - defaultMarket "cz" must name one of the markets (sk)`,
|
|
302
|
+
);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("builds account links on the market's domain outside development", () => {
|
|
306
|
+
const config = parseJarShopConfig(multiMarket);
|
|
307
|
+
const czech = config.markets[1]!;
|
|
308
|
+
const production = { APP_ENV: "production" };
|
|
309
|
+
expect(
|
|
310
|
+
storefrontMarketUrl(czech, "sk", "account/verify/complete", production),
|
|
311
|
+
).toBe("https://shop.example.cz/cs/account/verify/complete");
|
|
312
|
+
expect(
|
|
313
|
+
storefrontMarketUrl(czech, "en", "/account/verify/complete", production),
|
|
314
|
+
).toBe("https://shop.example.cz/en/account/verify/complete");
|
|
315
|
+
expect(
|
|
316
|
+
storefrontOriginForMarket(czech, {
|
|
317
|
+
APP_ENV: "dev",
|
|
318
|
+
JARSHOP_STOREFRONT_URL: "http://localhost:3001",
|
|
319
|
+
}).toString(),
|
|
320
|
+
).toBe("http://localhost:3001/");
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("keeps a market without domains on JARSHOP_STOREFRONT_URL", () => {
|
|
324
|
+
const single = parseJarShopConfig({
|
|
325
|
+
defaultMarket: "sk",
|
|
326
|
+
markets: [{ ...slovakia, domains: [] }],
|
|
327
|
+
});
|
|
328
|
+
expect(
|
|
329
|
+
storefrontMarketUrl(single.markets[0]!, "de", "account/x", {
|
|
330
|
+
APP_ENV: "production",
|
|
331
|
+
JARSHOP_STOREFRONT_URL: "https://eshop.example.sk",
|
|
332
|
+
}),
|
|
333
|
+
).toBe("https://eshop.example.sk/sk/account/x");
|
|
334
|
+
});
|
|
335
|
+
});
|