@lwc/sfdc-compiler-utils 2.19.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.
- package/LICENSE.txt +21 -0
- package/dist/__tests__/namespace.spec.d.ts +1 -0
- package/dist/__tests__/namespace.spec.js +462 -0
- package/dist/__tests__/namespace.spec.js.map +1 -0
- package/dist/__tests__/no-explicit-namespace.spec.d.ts +1 -0
- package/dist/__tests__/no-explicit-namespace.spec.js +258 -0
- package/dist/__tests__/no-explicit-namespace.spec.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/namespace-utils.d.ts +23 -0
- package/dist/namespace-utils.js +290 -0
- package/dist/namespace-utils.js.map +1 -0
- package/jest.config.js +6 -0
- package/package.json +15 -0
- package/src/__tests__/namespace.spec.ts +760 -0
- package/src/__tests__/no-explicit-namespace.spec.ts +350 -0
- package/src/index.ts +9 -0
- package/src/namespace-utils.ts +366 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,760 @@
|
|
|
1
|
+
import { getNamespacedIdForResource, getNamespacedIdForType } from '../namespace-utils';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_NAMESPACE_MAPPING = { c: 'nsC' };
|
|
4
|
+
|
|
5
|
+
describe('namespace', () => {
|
|
6
|
+
describe('invalid getNamespacedIdForType invocation', () => {
|
|
7
|
+
test('should error if "namespaceMapping" is not provided', () => {
|
|
8
|
+
expect(() => {
|
|
9
|
+
return getNamespacedIdForType('x/foo', 'module', undefined as any);
|
|
10
|
+
}).toThrowError(
|
|
11
|
+
'Failed to apply namespace mapping to "x/foo". Missing required "namespaceMapping" parameter'
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('should error if "moduleName" is not provided', () => {
|
|
16
|
+
expect(() => {
|
|
17
|
+
return getNamespacedIdForType(
|
|
18
|
+
undefined as any,
|
|
19
|
+
'module',
|
|
20
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
21
|
+
);
|
|
22
|
+
}).toThrowError(
|
|
23
|
+
'Failed to apply namespace mapping to "undefined". Missing required "moduleName" parameter'
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('should return undefined if resource is missing an "id"', () => {
|
|
28
|
+
expect(
|
|
29
|
+
getNamespacedIdForType('apex', 'apex', DEFAULT_NAMESPACE_MAPPING)
|
|
30
|
+
).toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('invalid getNamespacedIdForResource invocation', () => {
|
|
35
|
+
test('should error if "moduleName" is missing', () => {
|
|
36
|
+
expect(() => {
|
|
37
|
+
return getNamespacedIdForResource(undefined as any, DEFAULT_NAMESPACE_MAPPING);
|
|
38
|
+
}).toThrowError(
|
|
39
|
+
'Failed to apply namespace mapping to "undefined". Missing required "moduleName" parameter'
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('should error if "namespaceMapping" is missing', () => {
|
|
44
|
+
expect(() => {
|
|
45
|
+
return getNamespacedIdForResource('c/foo', undefined as any);
|
|
46
|
+
}).toThrowError(
|
|
47
|
+
'Failed to apply namespace mapping to "c/foo". Missing required "namespaceMapping" parameter'
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('should return undefined if no namespace mapping was matched', () => {
|
|
52
|
+
const actual = getNamespacedIdForResource('x/foo', DEFAULT_NAMESPACE_MAPPING);
|
|
53
|
+
expect(actual).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should return undefined if value contains extra separator', () => {
|
|
57
|
+
const actual = getNamespacedIdForResource('x//foo', DEFAULT_NAMESPACE_MAPPING);
|
|
58
|
+
expect(actual).toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('should return undefined if namespaceMapping does not have "c"', () => {
|
|
62
|
+
const actual = getNamespacedIdForResource('x/foo', { b: 'nsB' });
|
|
63
|
+
expect(actual).toBeUndefined();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('test noop resources', () => {
|
|
68
|
+
test('should return undefined when namespace mapping "accessCheck"', () => {
|
|
69
|
+
const actual = getNamespacedIdForType(
|
|
70
|
+
'@salesforce/accessCheck',
|
|
71
|
+
'accessCheck',
|
|
72
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
73
|
+
);
|
|
74
|
+
expect(actual).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('should return undefined when namespace mapping "client"', () => {
|
|
78
|
+
const actual = getNamespacedIdForType(
|
|
79
|
+
'@salesforce/client',
|
|
80
|
+
'client',
|
|
81
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
82
|
+
);
|
|
83
|
+
expect(actual).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('should return undefined when namespace mapping "commerce"', () => {
|
|
87
|
+
const actual = getNamespacedIdForType(
|
|
88
|
+
'@salesforce/commerce/webstoreId',
|
|
89
|
+
'commerce',
|
|
90
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
91
|
+
);
|
|
92
|
+
expect(actual).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('should return undefined when namespace mapping "community"', () => {
|
|
96
|
+
const actual = getNamespacedIdForType(
|
|
97
|
+
'@salesforce/community/Id',
|
|
98
|
+
'community',
|
|
99
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
100
|
+
);
|
|
101
|
+
expect(actual).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('should return undefined when namespace mapping "cssvars"', () => {
|
|
105
|
+
const actual = getNamespacedIdForType(
|
|
106
|
+
'@salesforce/cssvars/id',
|
|
107
|
+
'cssvars',
|
|
108
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
109
|
+
);
|
|
110
|
+
expect(actual).toBeUndefined();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('should return undefined when namespace mapping "gate"', () => {
|
|
114
|
+
const actual = getNamespacedIdForType(
|
|
115
|
+
'@salesforce/gate/foo.bar',
|
|
116
|
+
'gate',
|
|
117
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
118
|
+
);
|
|
119
|
+
expect(actual).toBeUndefined();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('should return undefined when namespace mapping "i18n"', () => {
|
|
123
|
+
const actual = getNamespacedIdForType(
|
|
124
|
+
'@salesforce/i18n/timezone',
|
|
125
|
+
'i18n',
|
|
126
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
127
|
+
);
|
|
128
|
+
expect(actual).toBeUndefined();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('should return undefined when namespace mapping "metric"', () => {
|
|
132
|
+
const actual = getNamespacedIdForType(
|
|
133
|
+
'@salesforce/metric/foo.bar',
|
|
134
|
+
'metric',
|
|
135
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
136
|
+
);
|
|
137
|
+
expect(actual).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('should return undefined when namespace mapping "internal"', () => {
|
|
141
|
+
const actual = getNamespacedIdForType(
|
|
142
|
+
'@salesforce/internal/core.appVersion',
|
|
143
|
+
'internal',
|
|
144
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
145
|
+
);
|
|
146
|
+
expect(actual).toBeUndefined();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('should return undefined when namespace mapping "site"', () => {
|
|
150
|
+
const actual = getNamespacedIdForType(
|
|
151
|
+
'@salesforce/site/Id',
|
|
152
|
+
'site',
|
|
153
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
154
|
+
);
|
|
155
|
+
expect(actual).toBeUndefined();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('should return undefined when namespace mapping "slds"', () => {
|
|
159
|
+
const actual = getNamespacedIdForType(
|
|
160
|
+
'@salesforce/slds/index.css',
|
|
161
|
+
'slds',
|
|
162
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
163
|
+
);
|
|
164
|
+
expect(actual).toBeUndefined();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('should return undefined when namespace mapping "user"', () => {
|
|
168
|
+
const actual = getNamespacedIdForType(
|
|
169
|
+
'@salesforce/user/id',
|
|
170
|
+
'user',
|
|
171
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
172
|
+
);
|
|
173
|
+
expect(actual).toBeUndefined();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('should return undefined when namespace mapping "userPermission"', () => {
|
|
177
|
+
const actual = getNamespacedIdForType(
|
|
178
|
+
'@salesforce/userPermission/perm',
|
|
179
|
+
'userPermission',
|
|
180
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
181
|
+
);
|
|
182
|
+
expect(actual).toBeUndefined();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe('namespace resource', () => {
|
|
187
|
+
test('should return namespacedId for non-salesforce resource', () => {
|
|
188
|
+
const expected = 'nsC/foo';
|
|
189
|
+
const actual = getNamespacedIdForType('c/foo', undefined, DEFAULT_NAMESPACE_MAPPING);
|
|
190
|
+
expect(actual).toBe(expected);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('should return "undefined" when namespace does not fully match "c"', () => {
|
|
194
|
+
const actual = getNamespacedIdForType('abc-utils', 'module', DEFAULT_NAMESPACE_MAPPING);
|
|
195
|
+
expect(actual).toBeUndefined();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('should return undefined if namespace match is not at the beginning of the module name', () => {
|
|
199
|
+
const actual = getNamespacedIdForType(
|
|
200
|
+
'./module/c-inner/property',
|
|
201
|
+
undefined,
|
|
202
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
203
|
+
);
|
|
204
|
+
expect(actual).toBeUndefined();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('namespace label resource', () => {
|
|
209
|
+
test('should return undefined if type is undefined for salesforce resource', () => {
|
|
210
|
+
const actual = getNamespacedIdForType('c.foo', undefined, DEFAULT_NAMESPACE_MAPPING);
|
|
211
|
+
expect(actual).toBeUndefined();
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('should return undefined if namespace value is empty', () => {
|
|
215
|
+
const actual = getNamespacedIdForType('.foo', 'label', DEFAULT_NAMESPACE_MAPPING);
|
|
216
|
+
expect(actual).toBeUndefined();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('should return undefined if namespace contains extra separator', () => {
|
|
220
|
+
const actual = getNamespacedIdForType('c..foo', 'label', DEFAULT_NAMESPACE_MAPPING);
|
|
221
|
+
expect(actual).toBeUndefined();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('should return undefined if resource has namespace but map does not have "c" mapping', () => {
|
|
225
|
+
const actual = getNamespacedIdForType('c.foo', 'label', { abc: 'nsC' });
|
|
226
|
+
expect(actual).toBe('c.foo');
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('should return existing namespace if default namespace has no mapping', () => {
|
|
230
|
+
const expected = '@salesforce/label/c.label';
|
|
231
|
+
const actual = getNamespacedIdForResource('@salesforce/label/c.label', { b: 'nsC' });
|
|
232
|
+
expect(actual).toBe(expected);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('should replace default namespace', () => {
|
|
236
|
+
const expected = '@salesforce/label/nsC.label';
|
|
237
|
+
const actual = getNamespacedIdForResource(
|
|
238
|
+
'@salesforce/label/c.label',
|
|
239
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
240
|
+
);
|
|
241
|
+
expect(actual).toBe(expected);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('should replace non-default namespace', () => {
|
|
245
|
+
const expected = '@salesforce/label/nsC.label';
|
|
246
|
+
const actual = getNamespacedIdForResource('@salesforce/label/custom.label', {
|
|
247
|
+
custom: 'nsC',
|
|
248
|
+
});
|
|
249
|
+
expect(actual).toBe(expected);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test('should return namespace if already present', () => {
|
|
253
|
+
const expected = '@salesforce/label/othernamespace.label';
|
|
254
|
+
const actual = getNamespacedIdForResource(
|
|
255
|
+
'@salesforce/label/othernamespace.label',
|
|
256
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
257
|
+
);
|
|
258
|
+
expect(actual).toBe(expected);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
describe('namespace resourceUrl resource', () => {
|
|
263
|
+
test('should add namespace if not present', () => {
|
|
264
|
+
const expected = '@salesforce/resourceUrl/nsC__resource';
|
|
265
|
+
const actual = getNamespacedIdForResource(
|
|
266
|
+
'@salesforce/resourceUrl/resource',
|
|
267
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
268
|
+
);
|
|
269
|
+
expect(actual).toBe(expected);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('should return undefined if namespace value is empty', () => {
|
|
273
|
+
const actual = getNamespacedIdForResource(
|
|
274
|
+
'@salesforce/resourceUrl/__resource',
|
|
275
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
276
|
+
);
|
|
277
|
+
expect(actual).toBeUndefined();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('should return undefined if namespace contains extra separator', () => {
|
|
281
|
+
const actual = getNamespacedIdForResource(
|
|
282
|
+
'@salesforce/resourceUrl/c____resource',
|
|
283
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
284
|
+
);
|
|
285
|
+
expect(actual).toBeUndefined();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('should replace default namespace', () => {
|
|
289
|
+
const expected = '@salesforce/resourceUrl/nsC__resource';
|
|
290
|
+
const actual = getNamespacedIdForResource(
|
|
291
|
+
'@salesforce/resourceUrl/c__resource',
|
|
292
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
293
|
+
);
|
|
294
|
+
expect(actual).toBe(expected);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test('should return existing namespace if default namespace has no mapping', () => {
|
|
298
|
+
const expected = '@salesforce/resourceUrl/c__resource';
|
|
299
|
+
const actual = getNamespacedIdForResource('@salesforce/resourceUrl/c__resource', {
|
|
300
|
+
b: 'nsC',
|
|
301
|
+
});
|
|
302
|
+
expect(actual).toBe(expected);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
test('should replace non-default namespace', () => {
|
|
306
|
+
const expected = '@salesforce/resourceUrl/nsC__resource';
|
|
307
|
+
const actual = getNamespacedIdForResource('@salesforce/resourceUrl/abc__resource', {
|
|
308
|
+
abc: 'nsC',
|
|
309
|
+
});
|
|
310
|
+
expect(actual).toBe(expected);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('should return namespace if already present', () => {
|
|
314
|
+
const expected = '@salesforce/resourceUrl/anotherNs__resource';
|
|
315
|
+
const actual = getNamespacedIdForResource(
|
|
316
|
+
'@salesforce/resourceUrl/anotherNs__resource',
|
|
317
|
+
{ c: 'anotherNs' }
|
|
318
|
+
);
|
|
319
|
+
expect(actual).toBe(expected);
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe('namespace contentAssetUrl resource', () => {
|
|
324
|
+
test('should add namespace if not present', () => {
|
|
325
|
+
const expected = '@salesforce/contentAssetUrl/nsC__asset';
|
|
326
|
+
const actual = getNamespacedIdForResource(
|
|
327
|
+
'@salesforce/contentAssetUrl/asset',
|
|
328
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
329
|
+
);
|
|
330
|
+
expect(actual).toBe(expected);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('should return namespace if already present', () => {
|
|
334
|
+
const expected = '@salesforce/contentAssetUrl/anotherNs__asset';
|
|
335
|
+
const actual = getNamespacedIdForResource(
|
|
336
|
+
'@salesforce/contentAssetUrl/anotherNs__asset',
|
|
337
|
+
{ c: 'anotherNs' }
|
|
338
|
+
);
|
|
339
|
+
expect(actual).toBe(expected);
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe('namespaced messageChannel resource', () => {
|
|
344
|
+
test('should return undefined if a non-custom (no __c) messageChannel is missing a namespace', () => {
|
|
345
|
+
const actual = getNamespacedIdForResource(
|
|
346
|
+
'@salesforce/messageChannel/message',
|
|
347
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
348
|
+
);
|
|
349
|
+
expect(actual).toBe(undefined);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('should return namespace when present for non-custom (no __c) messageChannels', () => {
|
|
353
|
+
const expected = '@salesforce/messageChannel/anotherNs__message';
|
|
354
|
+
const actual = getNamespacedIdForResource(
|
|
355
|
+
'@salesforce/messageChannel/anotherNs__message',
|
|
356
|
+
{ c: 'anotherNs' }
|
|
357
|
+
);
|
|
358
|
+
expect(actual).toBe(expected);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('should add namespace for custom message (__c) types if no namespace present', () => {
|
|
362
|
+
const expected = '@salesforce/messageChannel/nsC__message__c';
|
|
363
|
+
const actual = getNamespacedIdForResource(
|
|
364
|
+
'@salesforce/messageChannel/message__c',
|
|
365
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
366
|
+
);
|
|
367
|
+
expect(actual).toBe(expected);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('should return namespace when present for custom (__c) messageChannels', () => {
|
|
371
|
+
const expected = '@salesforce/messageChannel/anotherNs__message__c';
|
|
372
|
+
const actual = getNamespacedIdForResource(
|
|
373
|
+
'@salesforce/messageChannel/anotherNs__message__c',
|
|
374
|
+
{ c: 'anotherNs' }
|
|
375
|
+
);
|
|
376
|
+
expect(actual).toBe(expected);
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
describe('namespace customPermission resource', () => {
|
|
381
|
+
test('should add namespace if not present', () => {
|
|
382
|
+
const expected = '@salesforce/customPermission/nsC__perm';
|
|
383
|
+
const actual = getNamespacedIdForResource(
|
|
384
|
+
'@salesforce/customPermission/perm',
|
|
385
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
386
|
+
);
|
|
387
|
+
expect(actual).toBe(expected);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
test('should return namespace if already present', () => {
|
|
391
|
+
const expected = '@salesforce/customPermission/anotherNs__perm';
|
|
392
|
+
const actual = getNamespacedIdForResource(
|
|
393
|
+
'@salesforce/customPermission/anotherNs__perm',
|
|
394
|
+
{ c: 'anotherNs' }
|
|
395
|
+
);
|
|
396
|
+
expect(actual).toBe(expected);
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
describe('namespace komaci resource', () => {
|
|
401
|
+
test('should add namespace if not present', () => {
|
|
402
|
+
const expected = '@salesforce/komaci/nsC__resource';
|
|
403
|
+
const actual = getNamespacedIdForResource(
|
|
404
|
+
'@salesforce/komaci/resource',
|
|
405
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
406
|
+
);
|
|
407
|
+
expect(actual).toBe(expected);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test('should return namespace if already present', () => {
|
|
411
|
+
const expected = '@salesforce/komaci/anotherNs__resource';
|
|
412
|
+
const actual = getNamespacedIdForResource('@salesforce/komaci/anotherNs__resource', {
|
|
413
|
+
c: 'anotherNs',
|
|
414
|
+
});
|
|
415
|
+
expect(actual).toBe(expected);
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
describe('namespace apex resource', () => {
|
|
420
|
+
test('should return undefined if the namespace map is missing the default namespace', () => {
|
|
421
|
+
const actual = getNamespacedIdForResource('@salesforce/apex/MyClass.methodA', {
|
|
422
|
+
b: 'bNs',
|
|
423
|
+
});
|
|
424
|
+
expect(actual).toBeUndefined();
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test('should return undefined if namespace value is empty', () => {
|
|
428
|
+
const actual = getNamespacedIdForResource('@salesforce/apex/.methodA', { b: 'bNs' });
|
|
429
|
+
expect(actual).toBeUndefined();
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('should return undefined if namespace contains extra separator', () => {
|
|
433
|
+
const actual = getNamespacedIdForResource('@salesforce/apex/MyClass..methodA', {
|
|
434
|
+
b: 'bNs',
|
|
435
|
+
});
|
|
436
|
+
expect(actual).toBeUndefined();
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
test('should return undefined if apex resource does not have a method', () => {
|
|
440
|
+
expect(
|
|
441
|
+
getNamespacedIdForResource('@salesforce/apex/MyClass', { c: 'bNs' })
|
|
442
|
+
).toBeUndefined();
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test('should add namespace if not present', () => {
|
|
446
|
+
const expected = '@salesforce/apex/nsC.MyClass.methodA';
|
|
447
|
+
const actual = getNamespacedIdForResource(
|
|
448
|
+
'@salesforce/apex/MyClass.methodA',
|
|
449
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
450
|
+
);
|
|
451
|
+
expect(actual).toBe(expected);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test('should replace default namespace', () => {
|
|
455
|
+
const expected = '@salesforce/apex/nsC.MyClass.methodA';
|
|
456
|
+
const actual = getNamespacedIdForResource(
|
|
457
|
+
'@salesforce/apex/c.MyClass.methodA',
|
|
458
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
459
|
+
);
|
|
460
|
+
expect(actual).toBe(expected);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
test('c with no mapping', () => {
|
|
464
|
+
const actual = getNamespacedIdForResource('@salesforce/apex/c.MyClass.methodA', {});
|
|
465
|
+
expect(actual).toBe('@salesforce/apex/c.MyClass.methodA');
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
test('should replace non-default namespace', () => {
|
|
469
|
+
const expected = '@salesforce/apex/nsC.MyClass.methodA';
|
|
470
|
+
const actual = getNamespacedIdForResource('@salesforce/apex/abc.MyClass.methodA', {
|
|
471
|
+
abc: 'nsC',
|
|
472
|
+
});
|
|
473
|
+
expect(actual).toBe(expected);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
test('should return namespace if already present', () => {
|
|
477
|
+
const expected = '@salesforce/apex/anotherNamespace.MyClass.methodA';
|
|
478
|
+
const actual = getNamespacedIdForResource(
|
|
479
|
+
'@salesforce/apex/anotherNamespace.MyClass.methodA',
|
|
480
|
+
{ c: 'anotherNamespace' }
|
|
481
|
+
);
|
|
482
|
+
expect(actual).toBe(expected);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test('should return namespace if already present in resource and map', () => {
|
|
486
|
+
const expected = '@salesforce/apex/anotherNamespace.MyClass.methodA';
|
|
487
|
+
const actual = getNamespacedIdForResource(
|
|
488
|
+
'@salesforce/apex/anotherNamespace.MyClass.methodA',
|
|
489
|
+
{ anotherNamespace: 'anotherNamespace' }
|
|
490
|
+
);
|
|
491
|
+
expect(actual).toBe(expected);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
test('should return namespace if already present and map contains default mapping', () => {
|
|
495
|
+
const expected = '@salesforce/apex/anotherNamespace.MyClass.methodA';
|
|
496
|
+
const actual = getNamespacedIdForResource(
|
|
497
|
+
'@salesforce/apex/anotherNamespace.MyClass.methodA',
|
|
498
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
499
|
+
);
|
|
500
|
+
expect(actual).toBe(expected);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
test('should return undefined when provided empty namespace mapping', () => {
|
|
504
|
+
const actual = getNamespacedIdForResource('@salesforce/apex/MyClass.methodA', {});
|
|
505
|
+
expect(actual).toBeUndefined();
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
describe('namespace apexContinuation resource', () => {
|
|
510
|
+
test('should return undefined if the namespace map is missing the default namespace', () => {
|
|
511
|
+
const actual = getNamespacedIdForResource(
|
|
512
|
+
'@salesforce/apexContinuation/MyClass.methodA',
|
|
513
|
+
{ b: 'bNs' }
|
|
514
|
+
);
|
|
515
|
+
expect(actual).toBeUndefined();
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
test('should return undefined if namespace value is empty', () => {
|
|
519
|
+
const actual = getNamespacedIdForResource('@salesforce/apexContinuation/.methodA', {
|
|
520
|
+
b: 'bNs',
|
|
521
|
+
});
|
|
522
|
+
expect(actual).toBeUndefined();
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
test('should return undefined if namespace contains extra separator', () => {
|
|
526
|
+
const actual = getNamespacedIdForResource(
|
|
527
|
+
'@salesforce/apexContinuation/MyClass..methodA',
|
|
528
|
+
{ b: 'bNs' }
|
|
529
|
+
);
|
|
530
|
+
expect(actual).toBeUndefined();
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
test('should return undefined if apex resource does not have a method', () => {
|
|
534
|
+
expect(
|
|
535
|
+
getNamespacedIdForResource('@salesforce/apexContinuation/MyClass', { c: 'bNs' })
|
|
536
|
+
).toBeUndefined();
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
test('should add namespace if not present', () => {
|
|
540
|
+
const expected = '@salesforce/apexContinuation/nsC.MyClass.methodA';
|
|
541
|
+
const actual = getNamespacedIdForResource(
|
|
542
|
+
'@salesforce/apexContinuation/MyClass.methodA',
|
|
543
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
544
|
+
);
|
|
545
|
+
expect(actual).toBe(expected);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
test('should replace default namespace', () => {
|
|
549
|
+
const expected = '@salesforce/apexContinuation/nsC.MyClass.methodA';
|
|
550
|
+
const actual = getNamespacedIdForResource(
|
|
551
|
+
'@salesforce/apexContinuation/c.MyClass.methodA',
|
|
552
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
553
|
+
);
|
|
554
|
+
expect(actual).toBe(expected);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
test('c with no mapping', () => {
|
|
558
|
+
const actual = getNamespacedIdForResource(
|
|
559
|
+
'@salesforce/apexContinuation/c.MyClass.methodA',
|
|
560
|
+
{}
|
|
561
|
+
);
|
|
562
|
+
expect(actual).toBe('@salesforce/apexContinuation/c.MyClass.methodA');
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
test('should replace non-default namespace', () => {
|
|
566
|
+
const expected = '@salesforce/apexContinuation/nsC.MyClass.methodA';
|
|
567
|
+
const actual = getNamespacedIdForResource(
|
|
568
|
+
'@salesforce/apexContinuation/abc.MyClass.methodA',
|
|
569
|
+
{ abc: 'nsC' }
|
|
570
|
+
);
|
|
571
|
+
expect(actual).toBe(expected);
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
test('should return namespace if already present', () => {
|
|
575
|
+
const expected = '@salesforce/apexContinuation/anotherNamespace.MyClass.methodA';
|
|
576
|
+
const actual = getNamespacedIdForResource(
|
|
577
|
+
'@salesforce/apexContinuation/anotherNamespace.MyClass.methodA',
|
|
578
|
+
{ c: 'anotherNamespace' }
|
|
579
|
+
);
|
|
580
|
+
expect(actual).toBe(expected);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
test('should return namespace if already present in resource and map', () => {
|
|
584
|
+
const expected = '@salesforce/apexContinuation/anotherNamespace.MyClass.methodA';
|
|
585
|
+
const actual = getNamespacedIdForResource(
|
|
586
|
+
'@salesforce/apexContinuation/anotherNamespace.MyClass.methodA',
|
|
587
|
+
{ anotherNamespace: 'anotherNamespace' }
|
|
588
|
+
);
|
|
589
|
+
expect(actual).toBe(expected);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
test('should return namespace if already present and map contains default mapping', () => {
|
|
593
|
+
const expected = '@salesforce/apexContinuation/anotherNamespace.MyClass.methodA';
|
|
594
|
+
const actual = getNamespacedIdForResource(
|
|
595
|
+
'@salesforce/apexContinuation/anotherNamespace.MyClass.methodA',
|
|
596
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
597
|
+
);
|
|
598
|
+
expect(actual).toBe(expected);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
test('should return undefined when provided empty namespace mapping', () => {
|
|
602
|
+
const actual = getNamespacedIdForResource(
|
|
603
|
+
'@salesforce/apexContinuation/MyClass.methodA',
|
|
604
|
+
{}
|
|
605
|
+
);
|
|
606
|
+
expect(actual).toBeUndefined();
|
|
607
|
+
});
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
describe('namespace schema resource', () => {
|
|
611
|
+
test('should add namespace if not present', () => {
|
|
612
|
+
const expected = '@salesforce/schema/nsC__CustomObject__c';
|
|
613
|
+
const actual = getNamespacedIdForResource(
|
|
614
|
+
'@salesforce/schema/CustomObject__c',
|
|
615
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
616
|
+
);
|
|
617
|
+
expect(actual).toBe(expected);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
test('should return undefined if namespace value is empty', () => {
|
|
621
|
+
const actual = getNamespacedIdForResource(
|
|
622
|
+
'@salesforce/schema/__CustomObject__c',
|
|
623
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
624
|
+
);
|
|
625
|
+
expect(actual).toBeUndefined();
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
test('should return undefined if namespace contains extra separator', () => {
|
|
629
|
+
const actual = getNamespacedIdForResource(
|
|
630
|
+
'@salesforce/schema/c____CustomObject__c',
|
|
631
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
632
|
+
);
|
|
633
|
+
expect(actual).toBeUndefined();
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
test('should add namespace on custom fields on standard objects', () => {
|
|
637
|
+
const expected = '@salesforce/schema/Account.nsC__CustomField__c';
|
|
638
|
+
const actual = getNamespacedIdForResource(
|
|
639
|
+
'@salesforce/schema/Account.CustomField__c',
|
|
640
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
641
|
+
);
|
|
642
|
+
expect(actual).toBe(expected);
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
test('should add namespace on custom relationships on standard object', () => {
|
|
646
|
+
const expected = '@salesforce/schema/Account.nsC__Relation__r.Name';
|
|
647
|
+
const actual = getNamespacedIdForResource(
|
|
648
|
+
'@salesforce/schema/Account.Relation__r.Name',
|
|
649
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
650
|
+
);
|
|
651
|
+
expect(actual).toBe(expected);
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
test('should ignore standard object and relationships', () => {
|
|
655
|
+
const expected = '@salesforce/schema/Contact.Account.Name';
|
|
656
|
+
const actual = getNamespacedIdForResource(
|
|
657
|
+
'@salesforce/schema/Contact.Account.Name',
|
|
658
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
659
|
+
);
|
|
660
|
+
expect(actual).toBe(expected);
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
test('should handle mixed standard and custom relationships', () => {
|
|
664
|
+
const expected =
|
|
665
|
+
'@salesforce/schema/nsC__CustomObject__c.nsC__parentContact__r.Account.Name';
|
|
666
|
+
const actual = getNamespacedIdForResource(
|
|
667
|
+
'@salesforce/schema/CustomObject__c.parentContact__r.Account.Name',
|
|
668
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
669
|
+
);
|
|
670
|
+
expect(actual).toBe(expected);
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
test('should not add a namespace to a custom object with an existing namespace', () => {
|
|
674
|
+
const expected = '@salesforce/schema/ns__CustomObject__c';
|
|
675
|
+
const actual = getNamespacedIdForResource(
|
|
676
|
+
'@salesforce/schema/ns__CustomObject__c',
|
|
677
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
678
|
+
);
|
|
679
|
+
expect(actual).toBe(expected);
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
test('should replace namespace in a custom object with non-default namespace', () => {
|
|
683
|
+
const expected = '@salesforce/schema/nsC__CustomObject__c';
|
|
684
|
+
const actual = getNamespacedIdForResource('@salesforce/schema/ns__CustomObject__c', {
|
|
685
|
+
ns: 'nsC',
|
|
686
|
+
});
|
|
687
|
+
expect(actual).toBe(expected);
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
test('should not add a namespace to a custom field with an existing namespace', () => {
|
|
691
|
+
const expected = '@salesforce/schema/Account.ns__CustomField__c';
|
|
692
|
+
const actual = getNamespacedIdForResource(
|
|
693
|
+
'@salesforce/schema/Account.ns__CustomField__c',
|
|
694
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
695
|
+
);
|
|
696
|
+
expect(actual).toBe(expected);
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
test('should replace namespace in a custom field with a non-default namespace', () => {
|
|
700
|
+
const expected = '@salesforce/schema/Account.nsC__CustomField__c';
|
|
701
|
+
const actual = getNamespacedIdForResource(
|
|
702
|
+
'@salesforce/schema/Account.ns__CustomField__c',
|
|
703
|
+
{ ns: 'nsC' }
|
|
704
|
+
);
|
|
705
|
+
expect(actual).toBe(expected);
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
test('should not add a namespace to a custom relationship with an existing namespace', () => {
|
|
709
|
+
const expected = '@salesforce/schema/Account.ns__Relation__r.Name';
|
|
710
|
+
const actual = getNamespacedIdForResource(
|
|
711
|
+
'@salesforce/schema/Account.ns__Relation__r.Name',
|
|
712
|
+
DEFAULT_NAMESPACE_MAPPING
|
|
713
|
+
);
|
|
714
|
+
expect(actual).toBe(expected);
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
test('should replace namespace om a custom relationship with a non-default namespace', () => {
|
|
718
|
+
const expected = '@salesforce/schema/Account.nsC__Relation__r.Name';
|
|
719
|
+
const actual = getNamespacedIdForResource(
|
|
720
|
+
'@salesforce/schema/Account.ns__Relation__r.Name',
|
|
721
|
+
{ ns: 'nsC' }
|
|
722
|
+
);
|
|
723
|
+
expect(actual).toBe(expected);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
test('should return undefined if specified map is empty for one custom object', () => {
|
|
727
|
+
const actual = getNamespacedIdForResource('@salesforce/schema/Order_Item__c', {});
|
|
728
|
+
expect(actual).toBeUndefined();
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
test('should return undefined if specified map is empty for one custom object', () => {
|
|
732
|
+
const actual = getNamespacedIdForResource('@salesforce/schema/Order_Item__c', {});
|
|
733
|
+
expect(actual).toBeUndefined();
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
test('should return undefined if specified map is empty for two custom objects', () => {
|
|
737
|
+
const actual = getNamespacedIdForResource('@salesforce/schema/Product__c.MSRP__c', {});
|
|
738
|
+
expect(actual).toBeUndefined();
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
test('should return undefined if specified map is empty for two custom objects', () => {
|
|
742
|
+
expect(() => {
|
|
743
|
+
getNamespacedIdForResource(
|
|
744
|
+
'@salesforce/schema/Product__c.MSRP__c',
|
|
745
|
+
undefined as any
|
|
746
|
+
);
|
|
747
|
+
}).toThrow(
|
|
748
|
+
'Failed to apply namespace mapping to "@salesforce/schema/Product__c.MSRP__c".' +
|
|
749
|
+
' Missing required "namespaceMapping" parameter'
|
|
750
|
+
);
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
test('should return undefined if namespace map does not contain the match for two custom objects', () => {
|
|
754
|
+
const actual = getNamespacedIdForResource('@salesforce/schema/Product__c.MSRP__c', {
|
|
755
|
+
abd: 'nsC',
|
|
756
|
+
});
|
|
757
|
+
expect(actual).toBeUndefined();
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
});
|