@exdst-sitecore-content-sdk/astro 0.0.23 → 0.0.25
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/package.json +9 -14
- package/src/client/sitecore-astro-client.ts +0 -45
- package/src/context.ts +14 -16
- package/src/env.d.ts +1 -1
- package/src/sharedTypes/component-props.ts +0 -10
- package/src/tools/generate-map.ts +9 -21
- package/src/client/sitecore-astro-client.test.ts +0 -292
- package/src/components/AstroImage.astro.test.ts +0 -541
- package/src/components/Date.astro.test.ts +0 -197
- package/src/components/EditingScripts.astro.test.ts +0 -267
- package/src/components/ErrorBoundary.astro.test.ts +0 -252
- package/src/components/ErrorComponent.astro.test.ts +0 -31
- package/src/components/FieldMetadata.astro.test.ts +0 -40
- package/src/components/File.astro.test.ts +0 -68
- package/src/components/HiddenRendering.astro.test.ts +0 -36
- package/src/components/Image.astro.test.ts +0 -438
- package/src/components/Link.astro.test.ts +0 -261
- package/src/components/MissingComponent.astro.test.ts +0 -21
- package/src/components/Placeholder/Placeholder.astro.test.ts +0 -1088
- package/src/components/Placeholder/PlaceholderMetadata.astro.test.ts +0 -228
- package/src/components/Placeholder/PlaceholderUtils.astro.test.ts +0 -149
- package/src/components/Placeholder/placeholder-utils.test.ts +0 -309
- package/src/components/RichText.astro.test.ts +0 -205
- package/src/components/Text.astro.test.ts +0 -273
- package/src/config/define-config.test.ts +0 -526
- package/src/config-cli/define-cli-config.test.ts +0 -88
- package/src/editing/editing-config-middleware.test.ts +0 -164
- package/src/editing/editing-render-middleware.test.ts +0 -1143
- package/src/editing/render-middleware.test.ts +0 -57
- package/src/editing/utils.test.ts +0 -1212
- package/src/enhancers/WithEmptyFieldEditingComponent.astro.test.ts +0 -380
- package/src/enhancers/WithFieldMetadata.astro.test.ts +0 -113
- package/src/middleware/middleware.test.ts +0 -520
- package/src/middleware/multisite-middleware.test.ts +0 -667
- package/src/middleware/robots-middleware.test.ts +0 -129
- package/src/middleware/sitemap-middleware.test.ts +0 -184
- package/src/services/component-props-service.ts +0 -183
- package/src/tests/astro-helpers.ts +0 -61
- package/src/tests/helpers.ts +0 -46
- package/src/tests/personalizeData.ts +0 -63
- package/src/tests/test-components/CustomErrorComponent.astro +0 -3
- package/src/tests/test-components/CustomHiddenRendering.astro +0 -10
- package/src/tests/test-components/CustomMissingComponent.astro +0 -9
- package/src/tests/test-components/DownloadCallout.astro +0 -12
- package/src/tests/test-components/EmptyFieldEditingComponent.astro +0 -5
- package/src/tests/test-components/ErrorBoundaryWithError.astro +0 -10
- package/src/tests/test-components/Home.astro +0 -12
- package/src/tests/test-components/SxaRichText.astro +0 -23
- package/src/tests/test-components/SxaRichTextDefault.astro +0 -7
- package/src/tests/test-components/SxaRichTextWithTitle.astro +0 -8
- package/src/tests/test-components/TestComponent.astro +0 -9
- package/src/tests/test-components/TestComponentWithError.astro +0 -4
- package/src/tests/test-components/TestComponentWithField.astro +0 -17
- package/src/tests/test-components/TestHeader.astro +0 -8
- package/src/tests/test-components/TestLogo.astro +0 -5
- package/src/tests/test-components/TestParentWrapperComponent.astro +0 -5
- package/src/tests/test-components/TestWrapperComponent.astro +0 -5
- package/src/tests/test-components/map-components/Bar.astro +0 -0
- package/src/tests/test-components/map-components/Baz.astro +0 -0
- package/src/tests/test-components/map-components/Foo.astro +0 -0
- package/src/tests/test-components/map-components/Hero.variant.astro +0 -0
- package/src/tests/test-components/map-components/NotComponent.bsx +0 -0
- package/src/tests/test-components/map-components/Qux.astro +0 -0
- package/src/tests/test-components/map-components/folded/Folded.astro +0 -0
- package/src/tests/test-components/map-components/folded/random-file-2.docx +0 -0
- package/src/tests/test-components/map-components/random-file.txt +0 -0
- package/src/tests/test-data/metadata-data.ts +0 -86
- package/src/tests/test-data/normal-mode-data.ts +0 -466
- package/src/tests/vitest.setup.ts +0 -4
- package/src/tools/templating/components.test.ts +0 -318
- package/src/tools/templating/default-component.test.ts +0 -31
- package/src/utils/utils.test.ts +0 -48
|
@@ -1,526 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-expressions, @typescript-eslint/no-unused-expressions */
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import sinon from 'sinon';
|
|
4
|
-
import proxyquire from 'proxyquire';
|
|
5
|
-
|
|
6
|
-
describe('defineConfig', () => {
|
|
7
|
-
let defineConfigCoreStub: sinon.SinonStub;
|
|
8
|
-
let defineConfigModule: any;
|
|
9
|
-
const sandbox = sinon.createSandbox();
|
|
10
|
-
const defaultConfig = () => ({
|
|
11
|
-
api: {
|
|
12
|
-
edge: { contextId: 'contextId' },
|
|
13
|
-
},
|
|
14
|
-
defaultLanguage: 'en',
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
defineConfigCoreStub = sandbox.stub();
|
|
19
|
-
defineConfigModule = proxyquire('./define-config', {
|
|
20
|
-
'@sitecore-content-sdk/content/config': {
|
|
21
|
-
defineConfig: defineConfigCoreStub,
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
sandbox.restore();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('config.api.edge.contextid', () => {
|
|
31
|
-
describe('environment variable is not set', () => {
|
|
32
|
-
it('should default to empty string', () => {
|
|
33
|
-
defineConfigModule.defineConfig({
|
|
34
|
-
api: {
|
|
35
|
-
local: { apiHost: 'apihost', apiKey: 'apikey' },
|
|
36
|
-
},
|
|
37
|
-
defaultLanguage: 'en',
|
|
38
|
-
});
|
|
39
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
40
|
-
expect(resultConfig.api?.edge?.contextId).to.equal('');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should use the value from the config', () => {
|
|
44
|
-
defineConfigModule.defineConfig({
|
|
45
|
-
api: {
|
|
46
|
-
edge: { contextId: 'custom-context-id' },
|
|
47
|
-
},
|
|
48
|
-
defaultLanguage: 'en',
|
|
49
|
-
});
|
|
50
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
51
|
-
expect(resultConfig.api?.edge?.contextId).to.equal('custom-context-id');
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('environment variable is set', () => {
|
|
56
|
-
before(() => {
|
|
57
|
-
process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID = 'next-public-sitecore-edge-context-id';
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
after(() => {
|
|
61
|
-
delete process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should use the value from the config if present', () => {
|
|
65
|
-
defineConfigModule.defineConfig({
|
|
66
|
-
api: {
|
|
67
|
-
edge: { contextId: 'custom-context-id' },
|
|
68
|
-
},
|
|
69
|
-
defaultLanguage: 'en',
|
|
70
|
-
});
|
|
71
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
72
|
-
expect(resultConfig.api?.edge?.contextId).to.equal('custom-context-id');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should NOT use the env var for server-side contextId', () => {
|
|
76
|
-
defineConfigModule.defineConfig({
|
|
77
|
-
api: {
|
|
78
|
-
local: { apiHost: 'apihost', apiKey: 'apikey' },
|
|
79
|
-
},
|
|
80
|
-
defaultLanguage: 'en',
|
|
81
|
-
});
|
|
82
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
83
|
-
expect(resultConfig.api?.edge?.contextId).to.equal('');
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('config.api.edge.clientContextId', () => {
|
|
89
|
-
describe('environment variable is not set', () => {
|
|
90
|
-
it('should default to undefined', () => {
|
|
91
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
92
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
93
|
-
expect(resultConfig.api?.edge?.clientContextId).to.be.undefined;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should use the value from the config', () => {
|
|
97
|
-
defineConfigModule.defineConfig({
|
|
98
|
-
...defaultConfig(),
|
|
99
|
-
api: {
|
|
100
|
-
edge: {
|
|
101
|
-
contextId: 'context-id',
|
|
102
|
-
clientContextId: 'clien-context-id',
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
107
|
-
expect(resultConfig.api?.edge?.clientContextId).to.equal('clien-context-id');
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe('environment variable is set', () => {
|
|
111
|
-
before(() => {
|
|
112
|
-
process.env.PUBLIC_SITECORE_EDGE_CONTEXT_ID = 'next-public-sitecore-edge-context-id';
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
after(() => {
|
|
116
|
-
delete process.env.PUBLIC_SITECORE_EDGE_CONTEXT_ID;
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should use the value from the config if present', () => {
|
|
120
|
-
defineConfigModule.defineConfig({
|
|
121
|
-
api: {
|
|
122
|
-
edge: {
|
|
123
|
-
contextId: 'custom-context-id',
|
|
124
|
-
clientContextId: 'custom-client-context-id',
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
defaultLanguage: 'en',
|
|
128
|
-
});
|
|
129
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
130
|
-
expect(resultConfig.api?.edge?.clientContextId).to.equal('custom-client-context-id');
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should use the env var for client-side contextId only', () => {
|
|
134
|
-
defineConfigModule.defineConfig({
|
|
135
|
-
api: {
|
|
136
|
-
local: { apiHost: 'apihost', apiKey: 'apikey' },
|
|
137
|
-
},
|
|
138
|
-
defaultLanguage: 'en',
|
|
139
|
-
});
|
|
140
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
141
|
-
// Server-side contextId should be empty
|
|
142
|
-
expect(resultConfig.api?.edge?.contextId).to.equal('');
|
|
143
|
-
// Client-side contextId should use env var
|
|
144
|
-
expect(resultConfig.api?.edge?.clientContextId).to.equal(
|
|
145
|
-
'next-public-sitecore-edge-context-id'
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('config.api.edge.edgeUrl', () => {
|
|
152
|
-
describe('environment variable is not set', () => {
|
|
153
|
-
it('should default to Edge Platform URL', () => {
|
|
154
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
155
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
156
|
-
expect(resultConfig.api?.edge?.edgeUrl).to.equal('https://edge-platform.sitecorecloud.io');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should use the value from the config', () => {
|
|
160
|
-
defineConfigModule.defineConfig({
|
|
161
|
-
...defaultConfig(),
|
|
162
|
-
api: { edge: { contextId: 'context-id', edgeUrl: 'edgeUrl' } },
|
|
163
|
-
});
|
|
164
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
165
|
-
expect(resultConfig.api?.edge?.edgeUrl).to.equal('edgeUrl');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
describe('environment variable is set', () => {
|
|
169
|
-
before(() => {
|
|
170
|
-
process.env.PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME = 'next-public-sitecore-edgeUrl';
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
after(() => {
|
|
174
|
-
delete process.env.PUBLIC_SITECORE_EDGE_PLATFORM_HOSTNAME;
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('should use the value from the config if present', () => {
|
|
178
|
-
defineConfigModule.defineConfig({
|
|
179
|
-
api: {
|
|
180
|
-
edge: { contextId: 'custom-context-id', edgeUrl: 'custom-edgeUrl' },
|
|
181
|
-
},
|
|
182
|
-
defaultLanguage: 'en',
|
|
183
|
-
});
|
|
184
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
185
|
-
expect(resultConfig.api?.edge?.edgeUrl).to.equal('custom-edgeUrl');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should use the env var if present', () => {
|
|
189
|
-
defineConfigModule.defineConfig({
|
|
190
|
-
api: {
|
|
191
|
-
local: { apiHost: 'apihost', apiKey: 'apikey' },
|
|
192
|
-
},
|
|
193
|
-
defaultLanguage: 'en',
|
|
194
|
-
});
|
|
195
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
196
|
-
expect(resultConfig.api?.edge?.edgeUrl).to.equal('next-public-sitecore-edgeUrl');
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
describe('config.api.local', () => {
|
|
202
|
-
describe('environment variables are not set', () => {
|
|
203
|
-
it('should default to empty string', () => {
|
|
204
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
205
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
206
|
-
expect(resultConfig.api?.local?.apiKey).to.be.equal('');
|
|
207
|
-
expect(resultConfig.api?.local?.apiHost).to.be.equal('');
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('should use the value from the config', () => {
|
|
211
|
-
defineConfigModule.defineConfig({
|
|
212
|
-
...defaultConfig(),
|
|
213
|
-
api: { local: { apiKey: 'apiKey', apiHost: 'apiHost' } },
|
|
214
|
-
});
|
|
215
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
216
|
-
expect(resultConfig.api?.local?.apiKey).to.equal('apiKey');
|
|
217
|
-
expect(resultConfig.api?.local?.apiHost).to.equal('apiHost');
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
describe('environment variables are set', () => {
|
|
222
|
-
before(() => {
|
|
223
|
-
process.env.PUBLIC_SITECORE_API_KEY = 'next-public-sitecore-api-key';
|
|
224
|
-
process.env.PUBLIC_SITECORE_API_HOST = 'next-public-sitecore-api-host';
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
after(() => {
|
|
228
|
-
delete process.env.PUBLIC_SITECORE_API_KEY;
|
|
229
|
-
delete process.env.PUBLIC_SITECORE_API_HOST;
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('should use the values from the config if present', () => {
|
|
233
|
-
defineConfigModule.defineConfig({
|
|
234
|
-
...defaultConfig(),
|
|
235
|
-
api: { local: { apiKey: 'apiKey', apiHost: 'apiHost' } },
|
|
236
|
-
});
|
|
237
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
238
|
-
expect(resultConfig.api?.local?.apiKey).to.equal('apiKey');
|
|
239
|
-
expect(resultConfig.api?.local?.apiHost).to.equal('apiHost');
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('should use the env vars if present', () => {
|
|
243
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
244
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
245
|
-
expect(resultConfig.api?.local?.apiKey).to.equal('next-public-sitecore-api-key');
|
|
246
|
-
expect(resultConfig.api?.local?.apiHost).to.equal('next-public-sitecore-api-host');
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
describe('config.defaultSite', () => {
|
|
252
|
-
describe('environment variable is not set', () => {
|
|
253
|
-
it('should default to undefined', () => {
|
|
254
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
255
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
256
|
-
expect(resultConfig.defaultSite).to.equal('');
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('should use the value from the config', () => {
|
|
260
|
-
defineConfigModule.defineConfig({
|
|
261
|
-
...defaultConfig(),
|
|
262
|
-
defaultSite: 'skate-park',
|
|
263
|
-
});
|
|
264
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
265
|
-
expect(resultConfig.defaultSite).to.equal('skate-park');
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
describe('environment variable is set', () => {
|
|
270
|
-
before(() => {
|
|
271
|
-
process.env.PUBLIC_DEFAULT_SITE_NAME = 'next-public-sitecore-site-name';
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
after(() => {
|
|
275
|
-
delete process.env.PUBLIC_DEFAULT_SITE_NAME;
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('should use the value from the config if present', () => {
|
|
279
|
-
defineConfigModule.defineConfig({
|
|
280
|
-
...defaultConfig(),
|
|
281
|
-
defaultSite: 'skate-park',
|
|
282
|
-
});
|
|
283
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
284
|
-
expect(resultConfig.defaultSite).to.equal('skate-park');
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should use the env var if config value not present', () => {
|
|
288
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
289
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
290
|
-
expect(resultConfig.defaultSite).to.equal('next-public-sitecore-site-name');
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
describe('config.defaultLanguage', () => {
|
|
296
|
-
describe('environment variable is not set', () => {
|
|
297
|
-
it('should default to undefined', () => {
|
|
298
|
-
defineConfigModule.defineConfig({
|
|
299
|
-
api: {
|
|
300
|
-
edge: { contextId: 'contextId' },
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
304
|
-
expect(resultConfig.defaultLanguage).to.equal('en');
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it('should use the value from the config', () => {
|
|
308
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
309
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
310
|
-
expect(resultConfig.defaultLanguage).to.equal('en');
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
describe('environment variable is set', () => {
|
|
315
|
-
before(() => {
|
|
316
|
-
process.env.PUBLIC_DEFAULT_LANGUAGE = 'de';
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
after(() => {
|
|
320
|
-
delete process.env.PUBLIC_DEFAULT_LANGUAGE;
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it('should use the value from the config if present', () => {
|
|
324
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
325
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
326
|
-
expect(resultConfig.defaultLanguage).to.equal('en');
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it('should use the env var if config value not present', () => {
|
|
330
|
-
defineConfigModule.defineConfig({
|
|
331
|
-
api: {
|
|
332
|
-
edge: { contextId: 'contextId' },
|
|
333
|
-
},
|
|
334
|
-
});
|
|
335
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
336
|
-
expect(resultConfig.defaultLanguage).to.equal('de');
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
describe('config.multisite', () => {
|
|
342
|
-
describe('enabled', () => {
|
|
343
|
-
it('should default to undefined', () => {
|
|
344
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
345
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
346
|
-
expect(resultConfig.multisite?.enabled).to.be.undefined;
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('should be able to override default value of enabled', () => {
|
|
350
|
-
defineConfigModule.defineConfig({
|
|
351
|
-
...defaultConfig(),
|
|
352
|
-
multisite: { enabled: false },
|
|
353
|
-
});
|
|
354
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
355
|
-
expect(resultConfig.multisite?.enabled).to.be.false;
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
describe('useCookieResolution', () => {
|
|
360
|
-
it('cookie resolution should return default function', () => {
|
|
361
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
362
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
363
|
-
expect(resultConfig.multisite?.useCookieResolution).to.be.a('function');
|
|
364
|
-
|
|
365
|
-
if (resultConfig.multisite?.useCookieResolution) {
|
|
366
|
-
process.env.VERCEL_ENV = 'preview';
|
|
367
|
-
expect(resultConfig.multisite.useCookieResolution()).to.be.true;
|
|
368
|
-
delete process.env.VERCEL_ENV;
|
|
369
|
-
expect(resultConfig.multisite.useCookieResolution()).to.be.false;
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it('it should be able to override cookie resolution function', () => {
|
|
374
|
-
defineConfigModule.defineConfig({
|
|
375
|
-
...defaultConfig(),
|
|
376
|
-
multisite: { useCookieResolution: () => true },
|
|
377
|
-
});
|
|
378
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
379
|
-
expect(resultConfig.multisite?.useCookieResolution).to.be.a('function');
|
|
380
|
-
if (resultConfig.multisite?.useCookieResolution) {
|
|
381
|
-
expect(resultConfig.multisite.useCookieResolution()).to.be.true;
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
describe('config.personalize', () => {
|
|
388
|
-
describe('scope', () => {
|
|
389
|
-
describe('environment variable is not set', () => {
|
|
390
|
-
it('should default to undefined', () => {
|
|
391
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
392
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
393
|
-
expect(resultConfig.personalize?.scope).to.be.undefined;
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
it('should use the value from the config', () => {
|
|
397
|
-
defineConfigModule.defineConfig({
|
|
398
|
-
...defaultConfig(),
|
|
399
|
-
personalize: { scope: 'custom-scope' },
|
|
400
|
-
});
|
|
401
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
402
|
-
expect(resultConfig.personalize?.scope).to.equal('custom-scope');
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
describe('environment variable is set', () => {
|
|
407
|
-
before(() => {
|
|
408
|
-
process.env.PUBLIC_PERSONALIZE_SCOPE = 'custom-env-scope';
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
after(() => {
|
|
412
|
-
delete process.env.PUBLIC_PERSONALIZE_SCOPE;
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it('should use the value from the config if present', () => {
|
|
416
|
-
defineConfigModule.defineConfig({
|
|
417
|
-
...defaultConfig(),
|
|
418
|
-
personalize: { scope: 'custom-scope' },
|
|
419
|
-
});
|
|
420
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
421
|
-
expect(resultConfig.personalize?.scope).to.equal('custom-scope');
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it('should use the env var if config value not present', () => {
|
|
425
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
426
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
427
|
-
expect(resultConfig.personalize?.scope).to.equal('custom-env-scope');
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
describe('config.generateStaticPaths', () => {
|
|
434
|
-
describe('environment variable is not set', () => {
|
|
435
|
-
it('should default to true', () => {
|
|
436
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
437
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
438
|
-
expect(resultConfig.generateStaticPaths).to.equal(true);
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it('should use the value from the config', () => {
|
|
442
|
-
defineConfigModule.defineConfig({
|
|
443
|
-
generateStaticPaths: false,
|
|
444
|
-
...defaultConfig(),
|
|
445
|
-
});
|
|
446
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
447
|
-
expect(resultConfig.generateStaticPaths).to.equal(false);
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
describe('environment variable is set', () => {
|
|
452
|
-
afterEach(() => {
|
|
453
|
-
delete process.env.GENERATE_STATIC_PATHS;
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
it('should return false when GENERATE_STATIC_PATHS is set to false', () => {
|
|
457
|
-
process.env.GENERATE_STATIC_PATHS = 'false';
|
|
458
|
-
|
|
459
|
-
defineConfigModule.defineConfig({
|
|
460
|
-
generateStaticPaths: true,
|
|
461
|
-
...defaultConfig(),
|
|
462
|
-
});
|
|
463
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
464
|
-
expect(resultConfig.generateStaticPaths).to.equal(false);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
it('should return true when GENERATE_STATIC_PATHS is set to true', () => {
|
|
468
|
-
process.env.GENERATE_STATIC_PATHS = 'true';
|
|
469
|
-
|
|
470
|
-
defineConfigModule.defineConfig({
|
|
471
|
-
generateStaticPaths: false,
|
|
472
|
-
...defaultConfig(),
|
|
473
|
-
});
|
|
474
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
475
|
-
expect(resultConfig.generateStaticPaths).to.equal(true);
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
it('should return false when GENERATE_STATIC_PATHS is set to any other value', () => {
|
|
479
|
-
process.env.GENERATE_STATIC_PATHS = 'some-other-value';
|
|
480
|
-
|
|
481
|
-
defineConfigModule.defineConfig({
|
|
482
|
-
generateStaticPaths: true,
|
|
483
|
-
...defaultConfig(),
|
|
484
|
-
});
|
|
485
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
486
|
-
expect(resultConfig.generateStaticPaths).to.equal(false);
|
|
487
|
-
});
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
describe('sitecoreInternalEditingHostUrl', () => {
|
|
491
|
-
describe('environment variable is not set', () => {
|
|
492
|
-
it('should default to undefined', () => {
|
|
493
|
-
defineConfigModule.defineConfig(defaultConfig());
|
|
494
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
495
|
-
expect(resultConfig.sitecoreInternalEditingHostUrl).to.be.undefined;
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
it('should use the value from the config', () => {
|
|
499
|
-
defineConfigModule.defineConfig({
|
|
500
|
-
sitecoreInternalEditingHostUrl: 'http://localhost:3000',
|
|
501
|
-
...defaultConfig(),
|
|
502
|
-
});
|
|
503
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
504
|
-
expect(resultConfig.sitecoreInternalEditingHostUrl).to.equal('http://localhost:3000');
|
|
505
|
-
});
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
describe('environment variable is set', () => {
|
|
509
|
-
afterEach(() => {
|
|
510
|
-
delete process.env.SITECORE_INTERNAL_EDITING_HOST_URL;
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
it('should return set value', () => {
|
|
514
|
-
process.env.SITECORE_INTERNAL_EDITING_HOST_URL = 'http://localhost:3000';
|
|
515
|
-
|
|
516
|
-
defineConfigModule.defineConfig({
|
|
517
|
-
generateStaticPaths: true,
|
|
518
|
-
...defaultConfig(),
|
|
519
|
-
});
|
|
520
|
-
const resultConfig = defineConfigCoreStub.getCalls()[0].args[0];
|
|
521
|
-
expect(resultConfig.sitecoreInternalEditingHostUrl).to.equal('http://localhost:3000');
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
});
|
|
526
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
import { defineCliConfig } from './define-cli-config';
|
|
3
|
-
import {
|
|
4
|
-
SitecoreCliConfigInput,
|
|
5
|
-
SitecoreCliConfig,
|
|
6
|
-
ComponentTemplateType,
|
|
7
|
-
} from '@sitecore-content-sdk/content/config';
|
|
8
|
-
import chalk from 'chalk';
|
|
9
|
-
|
|
10
|
-
describe('defineCliConfig', () => {
|
|
11
|
-
const validateDefaultTemplates = (result: SitecoreCliConfig) => {
|
|
12
|
-
expect(result.scaffold.templates[0].name).to.equal(ComponentTemplateType.DEFAULT);
|
|
13
|
-
const defaultTemplate = result.scaffold.templates[0].generateTemplate('ComponentName');
|
|
14
|
-
// expect(defaultTemplate).to.contain(
|
|
15
|
-
// // eslint-disable-next-line quotes
|
|
16
|
-
// `import { ComponentParams, ComponentRendering } from '@sitecore-content-sdk/nextjs';`
|
|
17
|
-
// );
|
|
18
|
-
expect(defaultTemplate).to.contain('ComponentName');
|
|
19
|
-
if (result.scaffold.templates[0].getNextSteps) {
|
|
20
|
-
const componentpath = 'src/components/ComponentName.astro';
|
|
21
|
-
expect(result.scaffold.templates[0].getNextSteps(componentpath)[0]).to.contain(
|
|
22
|
-
`* Implement the Astro component in ${chalk.green(componentpath)}`
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// expect(result.scaffold.templates[1].name).to.equal(ComponentTemplateType.BYOC);
|
|
27
|
-
// const byocTemplate = result.scaffold.templates[1].generateTemplate('ByocComponentName');
|
|
28
|
-
// expect(byocTemplate).to.contain(
|
|
29
|
-
// // eslint-disable-next-line quotes
|
|
30
|
-
// `import * as FEAAS from '@sitecore-feaas/clientside/react';`
|
|
31
|
-
// );
|
|
32
|
-
// expect(byocTemplate).to.contain('ByocComponentName');
|
|
33
|
-
|
|
34
|
-
// expect(result.scaffold.templates[1].generateTemplate('comp name')).to.contain(
|
|
35
|
-
// // eslint-disable-next-line quotes
|
|
36
|
-
// `import * as FEAAS from '@sitecore-feaas/clientside/react';`
|
|
37
|
-
// );
|
|
38
|
-
// if (result.scaffold.templates[1].getNextSteps) {
|
|
39
|
-
// expect(result.scaffold.templates[1].getNextSteps('componentpath')[0]).to.contain(
|
|
40
|
-
// '* Modify component registration through FEAAS.External.registerComponent if needed'
|
|
41
|
-
// );
|
|
42
|
-
// }
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
it('should add default and byoc scaffold templates', () => {
|
|
46
|
-
const inputConfig: SitecoreCliConfigInput = {
|
|
47
|
-
build: {
|
|
48
|
-
commands: [
|
|
49
|
-
() => {
|
|
50
|
-
return async () => {
|
|
51
|
-
Promise.resolve('test');
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
scaffold: {
|
|
57
|
-
templates: [{ name: 'existing template', generateTemplate: () => 'test' }],
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const result = defineCliConfig(inputConfig);
|
|
62
|
-
expect(result.scaffold.templates).to.have.lengthOf(2);
|
|
63
|
-
|
|
64
|
-
validateDefaultTemplates(result);
|
|
65
|
-
|
|
66
|
-
expect(result.scaffold.templates[1].name).to.equal('existing template');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should initialize scaffold object if not present', () => {
|
|
70
|
-
const inputConfig: SitecoreCliConfigInput = {
|
|
71
|
-
build: {
|
|
72
|
-
commands: [
|
|
73
|
-
() => {
|
|
74
|
-
return async () => {
|
|
75
|
-
Promise.resolve('test');
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const result = defineCliConfig(inputConfig);
|
|
83
|
-
|
|
84
|
-
expect(result.scaffold.templates).to.have.lengthOf(1);
|
|
85
|
-
|
|
86
|
-
validateDefaultTemplates(result);
|
|
87
|
-
});
|
|
88
|
-
});
|