@contrail/cli 3.6.0-alpha.f45f126 → 3.7.0-alpha.51db987
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 +182 -1
- package/dist/api/types.d.ts +35 -0
- package/dist/api/types.js +49 -1
- package/dist/auth/login.d.ts +1 -1
- package/dist/auth/login.js +46 -29
- package/dist/auth/login.spec.js +31 -15
- package/dist/auth/sign-in-error.d.ts +7 -0
- package/dist/auth/sign-in-error.js +24 -0
- package/dist/auth/sign-in-error.spec.d.ts +1 -0
- package/dist/auth/sign-in-error.spec.js +22 -0
- package/dist/auth/sso.d.ts +5 -3
- package/dist/auth/sso.js +34 -18
- package/dist/auth/sso.spec.js +63 -10
- package/dist/basecommand.d.ts +3 -0
- package/dist/basecommand.js +10 -3
- package/dist/commands/app/getApiKey.js +2 -2
- package/dist/commands/entities/create.d.ts +49 -0
- package/dist/commands/entities/create.js +618 -0
- package/dist/commands/entities/create.spec.d.ts +1 -0
- package/dist/commands/entities/create.spec.js +581 -0
- package/dist/commands/entities/delete.d.ts +20 -0
- package/dist/commands/entities/delete.js +146 -0
- package/dist/commands/entities/get.d.ts +25 -0
- package/dist/commands/entities/get.js +298 -0
- package/dist/commands/entities/grammar.spec.d.ts +1 -0
- package/dist/commands/entities/grammar.spec.js +79 -0
- package/dist/commands/entities/output.spec.d.ts +1 -0
- package/dist/commands/entities/output.spec.js +72 -0
- package/dist/commands/entities/update.d.ts +32 -0
- package/dist/commands/entities/update.js +212 -0
- package/dist/commands/login.js +1 -1
- package/dist/commands/webhooks/delete.js +2 -3
- package/dist/common.d.ts +10 -1
- package/dist/common.js +37 -1
- package/dist/common.spec.d.ts +1 -0
- package/dist/common.spec.js +40 -0
- package/dist/helpers/config/config.d.ts +3 -3
- package/dist/helpers/config/config.js +3 -3
- package/dist/helpers/entities/assortment-items.d.ts +11 -0
- package/dist/helpers/entities/assortment-items.js +76 -0
- package/dist/helpers/entities/batchFetch.d.ts +11 -0
- package/dist/helpers/entities/batchFetch.js +50 -0
- package/dist/helpers/entities/index.d.ts +3 -0
- package/dist/helpers/entities/index.js +6 -0
- package/dist/helpers/entities/items.d.ts +6 -0
- package/dist/helpers/entities/items.js +60 -0
- package/dist/helpers/entities/items.spec.d.ts +1 -0
- package/dist/helpers/entities/items.spec.js +19 -0
- package/dist/helpers/entities/project-items.d.ts +2 -0
- package/dist/helpers/entities/project-items.js +44 -0
- package/dist/helpers/file-helpers.d.ts +1 -0
- package/dist/helpers/file-helpers.js +20 -3
- package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
- package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
- package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
- package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
- package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
- package/dist/logger.js +4 -1
- package/dist/logger.spec.d.ts +1 -0
- package/dist/logger.spec.js +12 -0
- package/node_modules/@contrail/entity-compare/package.json +6 -3
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
- package/node_modules/@contrail/loader/lib/constants.js +1 -9
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
- package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
- package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
- package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
- package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
- package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
- package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
- package/oclif.manifest.json +449 -1
- package/package.json +6 -12
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("@contrail/types");
|
|
4
|
+
const create_1 = require("./create");
|
|
5
|
+
const propertySpecifications_1 = require("../../helpers/propertySpecifications/propertySpecifications");
|
|
6
|
+
describe('doesPropertyLevelMatchRole', () => {
|
|
7
|
+
it('should return true for exact matches', () => {
|
|
8
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OPTION, 'option')).toBe(true);
|
|
9
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.FAMILY, 'family')).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
it('should return false when propertyLevel does not match role', () => {
|
|
12
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OPTION, 'family')).toBe(false);
|
|
13
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.FAMILY, 'option')).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
it('should return true for ALL property level with any role', () => {
|
|
16
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.ALL, 'option')).toBe(true);
|
|
17
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.ALL, 'family')).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
it('should return true for OVERRIDABLE property level with any role', () => {
|
|
20
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OVERRIDABLE, 'option')).toBe(true);
|
|
21
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OVERRIDABLE, 'family')).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('Entity Creation E2E Happy Path', () => {
|
|
25
|
+
describe('pickRandomValueForProperty', () => {
|
|
26
|
+
const mockObjectReferencesCache = new Map();
|
|
27
|
+
const mockTypeReferencesCache = new Map();
|
|
28
|
+
it('should generate random string values for String property type', () => {
|
|
29
|
+
const property = {
|
|
30
|
+
slug: 'name',
|
|
31
|
+
propertyType: types_1.PropertyType.String,
|
|
32
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
33
|
+
};
|
|
34
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
35
|
+
expect(typeof result).toBe('string');
|
|
36
|
+
expect(result.length).toBeGreaterThan(0);
|
|
37
|
+
});
|
|
38
|
+
it('should generate random boolean values for Boolean property type', () => {
|
|
39
|
+
const property = {
|
|
40
|
+
slug: 'isActive',
|
|
41
|
+
propertyType: types_1.PropertyType.Boolean,
|
|
42
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
43
|
+
};
|
|
44
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
45
|
+
expect(typeof result).toBe('boolean');
|
|
46
|
+
});
|
|
47
|
+
it('should generate random number values for Number property type', () => {
|
|
48
|
+
const property = {
|
|
49
|
+
slug: 'quantity',
|
|
50
|
+
propertyType: types_1.PropertyType.Number,
|
|
51
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
52
|
+
};
|
|
53
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
54
|
+
expect(typeof result).toBe('number');
|
|
55
|
+
});
|
|
56
|
+
it('should generate random date string for Date property type', () => {
|
|
57
|
+
const property = {
|
|
58
|
+
slug: 'createdAt',
|
|
59
|
+
propertyType: types_1.PropertyType.Date,
|
|
60
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
61
|
+
};
|
|
62
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
63
|
+
expect(typeof result).toBe('string');
|
|
64
|
+
expect(new Date(result).toString()).not.toBe('Invalid Date');
|
|
65
|
+
});
|
|
66
|
+
it('should pick random option for SingleSelect property type', () => {
|
|
67
|
+
const options = [
|
|
68
|
+
{ value: 'red', display: 'Red' },
|
|
69
|
+
{ value: 'blue', display: 'Blue' },
|
|
70
|
+
{ value: 'green', display: 'Green' },
|
|
71
|
+
];
|
|
72
|
+
const property = {
|
|
73
|
+
slug: 'color',
|
|
74
|
+
propertyType: types_1.PropertyType.SingleSelect,
|
|
75
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
76
|
+
options,
|
|
77
|
+
};
|
|
78
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
79
|
+
expect(options.some((option) => option.value === result)).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
it('should pick random options for MultiSelect property type', () => {
|
|
82
|
+
const options = [
|
|
83
|
+
{ value: 'feature1', display: 'Feature 1' },
|
|
84
|
+
{ value: 'feature2', display: 'Feature 2' },
|
|
85
|
+
{ value: 'feature3', display: 'Feature 3' },
|
|
86
|
+
];
|
|
87
|
+
const property = {
|
|
88
|
+
slug: 'features',
|
|
89
|
+
propertyType: types_1.PropertyType.MultiSelect,
|
|
90
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
91
|
+
options,
|
|
92
|
+
};
|
|
93
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
94
|
+
expect(Array.isArray(result)).toBe(true);
|
|
95
|
+
expect(result.length).toBeGreaterThan(0);
|
|
96
|
+
result.forEach((value) => {
|
|
97
|
+
expect(options.some((option) => option.value === value)).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it('should return object reference ID for ObjectReference property type', () => {
|
|
101
|
+
const mockEntity = { id: 'test-id-123', name: 'Test Entity' };
|
|
102
|
+
const objectCache = new Map([['test-id-123', mockEntity]]);
|
|
103
|
+
mockObjectReferencesCache.set('custom-entity:test', objectCache);
|
|
104
|
+
const property = {
|
|
105
|
+
slug: 'parentId',
|
|
106
|
+
propertyType: types_1.PropertyType.ObjectReference,
|
|
107
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
108
|
+
referencedTypePath: 'custom-entity:test',
|
|
109
|
+
};
|
|
110
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
111
|
+
expect(result).toBe('test-id-123');
|
|
112
|
+
});
|
|
113
|
+
it('should return type reference ID for TypeReference property type', () => {
|
|
114
|
+
const mockType = { id: 'type-id-456', typePath: 'custom-entity:category' };
|
|
115
|
+
mockTypeReferencesCache.set('custom-entity:category', mockType);
|
|
116
|
+
const property = {
|
|
117
|
+
slug: 'categoryType',
|
|
118
|
+
propertyType: types_1.PropertyType.TypeReference,
|
|
119
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
120
|
+
referencedTypePath: 'custom-entity:category',
|
|
121
|
+
};
|
|
122
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
123
|
+
expect(result).toBe('type-id-456');
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('buildObjectReferenceCache', () => {
|
|
127
|
+
it('should build a cache from entities with IDs', () => {
|
|
128
|
+
const entities = [
|
|
129
|
+
{ id: 'entity-1', name: 'First Entity', type: 'test' },
|
|
130
|
+
{ id: 'entity-2', name: 'Second Entity', type: 'test' },
|
|
131
|
+
{ id: 'entity-3', name: 'Third Entity', type: 'test' },
|
|
132
|
+
];
|
|
133
|
+
const cache = (0, create_1.buildObjectReferenceCache)(entities);
|
|
134
|
+
expect(cache.size).toBe(3);
|
|
135
|
+
expect(cache.get('entity-1')).toEqual(entities[0]);
|
|
136
|
+
expect(cache.get('entity-2')).toEqual(entities[1]);
|
|
137
|
+
expect(cache.get('entity-3')).toEqual(entities[2]);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('getReferencedObjectPaths', () => {
|
|
141
|
+
it('should extract object reference paths from type properties', () => {
|
|
142
|
+
const mockType = {
|
|
143
|
+
id: 'test-type',
|
|
144
|
+
typePath: 'item',
|
|
145
|
+
typeProperties: [
|
|
146
|
+
{
|
|
147
|
+
slug: 'name',
|
|
148
|
+
propertyType: types_1.PropertyType.String,
|
|
149
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
slug: 'categoryId',
|
|
153
|
+
propertyType: types_1.PropertyType.ObjectReference,
|
|
154
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
155
|
+
referencedTypePath: 'custom-entity:category',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
slug: 'supplierId',
|
|
159
|
+
propertyType: types_1.PropertyType.ObjectReference,
|
|
160
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
161
|
+
referencedTypePath: 'custom-entity:supplier',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
slug: 'description',
|
|
165
|
+
propertyType: types_1.PropertyType.Text,
|
|
166
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
const referencedPaths = (0, create_1.getReferencedObjectPaths)(mockType);
|
|
171
|
+
expect(referencedPaths).toEqual(['custom-entity:category', 'custom-entity:supplier']);
|
|
172
|
+
});
|
|
173
|
+
it('should return empty array when no object references exist', () => {
|
|
174
|
+
const mockType = {
|
|
175
|
+
id: 'test-type',
|
|
176
|
+
typePath: 'item',
|
|
177
|
+
typeProperties: [
|
|
178
|
+
{
|
|
179
|
+
slug: 'name',
|
|
180
|
+
propertyType: types_1.PropertyType.String,
|
|
181
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
slug: 'isActive',
|
|
185
|
+
propertyType: types_1.PropertyType.Boolean,
|
|
186
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
expect((0, create_1.getReferencedObjectPaths)(mockType)).toEqual([]);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
describe('Integration: Complete entity creation flow', () => {
|
|
194
|
+
it('should create a complete entity with all property types populated', () => {
|
|
195
|
+
// Mock a comprehensive type with various property types
|
|
196
|
+
const mockType = {
|
|
197
|
+
id: 'comprehensive-type',
|
|
198
|
+
typePath: 'item',
|
|
199
|
+
typeProperties: [
|
|
200
|
+
{
|
|
201
|
+
slug: 'name',
|
|
202
|
+
propertyType: types_1.PropertyType.String,
|
|
203
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
slug: 'isActive',
|
|
207
|
+
propertyType: types_1.PropertyType.Boolean,
|
|
208
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
slug: 'quantity',
|
|
212
|
+
propertyType: types_1.PropertyType.Number,
|
|
213
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
slug: 'color',
|
|
217
|
+
propertyType: types_1.PropertyType.SingleSelect,
|
|
218
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
219
|
+
options: [
|
|
220
|
+
{ value: 'red', display: 'Red' },
|
|
221
|
+
{ value: 'blue', display: 'Blue' },
|
|
222
|
+
{ value: 'green', display: 'Green' },
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
slug: 'features',
|
|
227
|
+
propertyType: types_1.PropertyType.MultiSelect,
|
|
228
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
229
|
+
options: [
|
|
230
|
+
{ value: 'waterproof', display: 'Waterproof' },
|
|
231
|
+
{ value: 'durable', display: 'Durable' },
|
|
232
|
+
{ value: 'lightweight', display: 'Lightweight' },
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
};
|
|
237
|
+
// Create mock caches
|
|
238
|
+
const objectReferencesCache = new Map();
|
|
239
|
+
const typeReferencesCache = new Map();
|
|
240
|
+
// Generate random values for each property
|
|
241
|
+
const generatedEntity = {};
|
|
242
|
+
for (const property of mockType.typeProperties) {
|
|
243
|
+
const value = (0, create_1.pickRandomValueForProperty)(property, objectReferencesCache, typeReferencesCache);
|
|
244
|
+
generatedEntity[property.slug] = value;
|
|
245
|
+
}
|
|
246
|
+
// Verify all properties are populated with correct types
|
|
247
|
+
expect(typeof generatedEntity.name).toBe('string');
|
|
248
|
+
expect(generatedEntity.name.length).toBeGreaterThan(0);
|
|
249
|
+
expect(typeof generatedEntity.isActive).toBe('boolean');
|
|
250
|
+
expect(typeof generatedEntity.quantity).toBe('number');
|
|
251
|
+
expect(generatedEntity.quantity).toBeGreaterThanOrEqual(0);
|
|
252
|
+
expect(['red', 'blue', 'green']).toContain(generatedEntity.color);
|
|
253
|
+
expect(Array.isArray(generatedEntity.features)).toBe(true);
|
|
254
|
+
expect(generatedEntity.features.length).toBeGreaterThan(0);
|
|
255
|
+
generatedEntity.features.forEach((feature) => {
|
|
256
|
+
expect(['waterproof', 'durable', 'lightweight']).toContain(feature);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
describe('Property Specifications Integration', () => {
|
|
261
|
+
describe('parsePropertySpecificationsIntoMap', () => {
|
|
262
|
+
it('should parse simple property specifications', () => {
|
|
263
|
+
const specs = [
|
|
264
|
+
'name=Test Item',
|
|
265
|
+
'quantity=10',
|
|
266
|
+
'isActive=true',
|
|
267
|
+
];
|
|
268
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
269
|
+
expect(result.get('name')).toBe('Test Item');
|
|
270
|
+
expect(result.get('quantity')).toBe('10');
|
|
271
|
+
expect(result.get('isActive')).toBe('true');
|
|
272
|
+
});
|
|
273
|
+
it('should build roles arrays from repeated keys', () => {
|
|
274
|
+
const specs = ['roles=option', 'roles=family', 'name=Test'];
|
|
275
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
276
|
+
expect(result.get('roles')).toEqual(['option', 'family']);
|
|
277
|
+
expect(result.get('name')).toBe('Test');
|
|
278
|
+
});
|
|
279
|
+
it('should handle complex values with spaces and special characters', () => {
|
|
280
|
+
const specs = [
|
|
281
|
+
'description=This is a long description with spaces',
|
|
282
|
+
'hex=#FF0000',
|
|
283
|
+
];
|
|
284
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(specs);
|
|
285
|
+
expect(result.get('description')).toBe('This is a long description with spaces');
|
|
286
|
+
expect(result.get('hex')).toBe('#FF0000');
|
|
287
|
+
});
|
|
288
|
+
it('should throw error for invalid specifications', () => {
|
|
289
|
+
expect(() => (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(['invalid-spec'])).toThrow('Invalid property specification: invalid-spec');
|
|
290
|
+
expect(() => (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(['=value'])).toThrow('Invalid property specification: =value');
|
|
291
|
+
const result = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)(['key=']);
|
|
292
|
+
expect(result.get('key')).toBeUndefined();
|
|
293
|
+
expect(result.size).toBe(1);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
describe('isValidPropertySpecification', () => {
|
|
297
|
+
it('should validate correct property specifications', () => {
|
|
298
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('name=value')).toBe(true);
|
|
299
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('id=123')).toBe(true);
|
|
300
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('description=Long description with spaces')).toBe(true);
|
|
301
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('roles=option,family')).toBe(true);
|
|
302
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('key=')).toBe(true);
|
|
303
|
+
});
|
|
304
|
+
it('should reject most invalid property specifications', () => {
|
|
305
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('invalid')).toBe(false);
|
|
306
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('=')).toBe(false);
|
|
307
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('=value')).toBe(false);
|
|
308
|
+
expect((0, propertySpecifications_1.isValidPropertySpecification)('')).toBe(false);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
describe('Property specifications with entity creation', () => {
|
|
312
|
+
it('should apply property specifications to override random values', () => {
|
|
313
|
+
const propertySpecs = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)([
|
|
314
|
+
'name=Custom Name',
|
|
315
|
+
'quantity=42',
|
|
316
|
+
'isActive=true',
|
|
317
|
+
]);
|
|
318
|
+
// Simulate the property specification override logic
|
|
319
|
+
const entity = {};
|
|
320
|
+
// First generate random values (simulated)
|
|
321
|
+
entity.name = 'random-name';
|
|
322
|
+
entity.quantity = 99;
|
|
323
|
+
entity.isActive = false;
|
|
324
|
+
// Then apply property specifications
|
|
325
|
+
for (const [slug, value] of propertySpecs.entries()) {
|
|
326
|
+
entity[slug] = value;
|
|
327
|
+
}
|
|
328
|
+
expect(entity.name).toBe('Custom Name');
|
|
329
|
+
expect(entity.quantity).toBe('42'); // Note: type casting would happen in real implementation
|
|
330
|
+
expect(entity.isActive).toBe('true'); // Note: type casting would happen in real implementation
|
|
331
|
+
});
|
|
332
|
+
it('should handle roles property specification for filtering properties', () => {
|
|
333
|
+
const propertySpecs = (0, propertySpecifications_1.parsePropertySpecificationsIntoMap)([
|
|
334
|
+
'roles=option',
|
|
335
|
+
]);
|
|
336
|
+
const roles = [].concat(propertySpecs.get('roles'));
|
|
337
|
+
// Test that property level matching works with specified roles
|
|
338
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OPTION, roles[0])).toBe(true);
|
|
339
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.FAMILY, roles[0])).toBe(false);
|
|
340
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.ALL, roles[0])).toBe(true);
|
|
341
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OVERRIDABLE, roles[0])).toBe(true);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
describe('Error Handling and Edge Cases', () => {
|
|
346
|
+
describe('pickRandomValueForProperty error scenarios', () => {
|
|
347
|
+
const mockObjectReferencesCache = new Map();
|
|
348
|
+
const mockTypeReferencesCache = new Map();
|
|
349
|
+
it('should throw error for SingleSelect without options', () => {
|
|
350
|
+
const property = {
|
|
351
|
+
slug: 'color',
|
|
352
|
+
propertyType: types_1.PropertyType.SingleSelect,
|
|
353
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
354
|
+
// Missing options property
|
|
355
|
+
};
|
|
356
|
+
expect(() => (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache)).toThrow('Option set is required for SingleSelect property');
|
|
357
|
+
});
|
|
358
|
+
it('should throw error for MultiSelect without options', () => {
|
|
359
|
+
const property = {
|
|
360
|
+
slug: 'features',
|
|
361
|
+
propertyType: types_1.PropertyType.MultiSelect,
|
|
362
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
363
|
+
// Missing options property
|
|
364
|
+
};
|
|
365
|
+
expect(() => (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache)).toThrow('Option set is required for MultiSelect property');
|
|
366
|
+
});
|
|
367
|
+
it('should throw error for ObjectReference with missing cache', () => {
|
|
368
|
+
const property = {
|
|
369
|
+
slug: 'categoryId',
|
|
370
|
+
propertyType: types_1.PropertyType.ObjectReference,
|
|
371
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
372
|
+
referencedTypePath: 'custom-entity:nonexistent',
|
|
373
|
+
};
|
|
374
|
+
expect(() => (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache)).toThrow('No object references found for referencedTypePath: custom-entity:nonexistent');
|
|
375
|
+
});
|
|
376
|
+
it('should throw error for ObjectReference with empty cache', () => {
|
|
377
|
+
const emptyCache = new Map();
|
|
378
|
+
emptyCache.set('custom-entity:empty', new Map());
|
|
379
|
+
const property = {
|
|
380
|
+
slug: 'categoryId',
|
|
381
|
+
propertyType: types_1.PropertyType.ObjectReference,
|
|
382
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
383
|
+
referencedTypePath: 'custom-entity:empty',
|
|
384
|
+
};
|
|
385
|
+
expect(() => (0, create_1.pickRandomValueForProperty)(property, emptyCache, mockTypeReferencesCache)).toThrow('No object references found for referencedTypePath: custom-entity:empty');
|
|
386
|
+
});
|
|
387
|
+
it('should throw error for TypeReference with missing type', () => {
|
|
388
|
+
const property = {
|
|
389
|
+
slug: 'categoryType',
|
|
390
|
+
propertyType: types_1.PropertyType.TypeReference,
|
|
391
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
392
|
+
referencedTypePath: 'custom-entity:nonexistent',
|
|
393
|
+
};
|
|
394
|
+
expect(() => (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache)).toThrow('Referenced type not found for path: custom-entity:nonexistent');
|
|
395
|
+
});
|
|
396
|
+
it('should throw error for unsupported property type', () => {
|
|
397
|
+
const property = {
|
|
398
|
+
slug: 'unsupported',
|
|
399
|
+
propertyType: 'UnsupportedType',
|
|
400
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
401
|
+
};
|
|
402
|
+
expect(() => (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache)).toThrow('Cannot handle property type: UnsupportedType');
|
|
403
|
+
});
|
|
404
|
+
it('should handle Formula property type gracefully', () => {
|
|
405
|
+
const property = {
|
|
406
|
+
slug: 'calculatedValue',
|
|
407
|
+
propertyType: types_1.PropertyType.Formula,
|
|
408
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
409
|
+
};
|
|
410
|
+
const result = (0, create_1.pickRandomValueForProperty)(property, mockObjectReferencesCache, mockTypeReferencesCache);
|
|
411
|
+
expect(result).toBeUndefined();
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
describe('Cache building edge cases', () => {
|
|
415
|
+
it('should handle empty entities array', () => {
|
|
416
|
+
const cache = (0, create_1.buildObjectReferenceCache)([]);
|
|
417
|
+
expect(cache.size).toBe(0);
|
|
418
|
+
});
|
|
419
|
+
it('should handle entities without IDs gracefully', () => {
|
|
420
|
+
const entitiesWithoutIds = [
|
|
421
|
+
{ name: 'Entity 1' },
|
|
422
|
+
{ id: 'entity-2', name: 'Entity 2' },
|
|
423
|
+
undefined, // Undefined entity
|
|
424
|
+
].filter(Boolean); // Remove undefined
|
|
425
|
+
const cache = (0, create_1.buildObjectReferenceCache)(entitiesWithoutIds);
|
|
426
|
+
expect(cache.size).toBe(1); // Only the valid entity with ID
|
|
427
|
+
expect(cache.get('entity-2')).toEqual({ id: 'entity-2', name: 'Entity 2' });
|
|
428
|
+
});
|
|
429
|
+
it('should handle duplicate entity IDs', () => {
|
|
430
|
+
const entitiesWithDuplicates = [
|
|
431
|
+
{ id: 'duplicate-id', name: 'First Entity' },
|
|
432
|
+
{ id: 'duplicate-id', name: 'Second Entity' },
|
|
433
|
+
{ id: 'unique-id', name: 'Unique Entity' },
|
|
434
|
+
];
|
|
435
|
+
const cache = (0, create_1.buildObjectReferenceCache)(entitiesWithDuplicates);
|
|
436
|
+
expect(cache.size).toBe(2);
|
|
437
|
+
// Should keep the first occurrence
|
|
438
|
+
expect(cache.get('duplicate-id')).toEqual({ id: 'duplicate-id', name: 'First Entity' });
|
|
439
|
+
expect(cache.get('unique-id')).toEqual({ id: 'unique-id', name: 'Unique Entity' });
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
describe('Reference path extraction edge cases', () => {
|
|
443
|
+
it('should handle type with no properties', () => {
|
|
444
|
+
const typeWithNoProperties = {
|
|
445
|
+
id: 'empty-type',
|
|
446
|
+
typePath: 'item',
|
|
447
|
+
typeProperties: [],
|
|
448
|
+
};
|
|
449
|
+
const referencedPaths = (0, create_1.getReferencedObjectPaths)(typeWithNoProperties);
|
|
450
|
+
expect(referencedPaths).toEqual([]);
|
|
451
|
+
});
|
|
452
|
+
it('should handle type with undefined typeProperties', () => {
|
|
453
|
+
const typeWithUndefinedProperties = {
|
|
454
|
+
id: 'undefined-props-type',
|
|
455
|
+
typePath: 'item',
|
|
456
|
+
typeProperties: undefined,
|
|
457
|
+
};
|
|
458
|
+
const referencedPaths = (0, create_1.getReferencedObjectPaths)(typeWithUndefinedProperties);
|
|
459
|
+
expect(referencedPaths).toEqual([]);
|
|
460
|
+
});
|
|
461
|
+
it('should filter out non-ObjectReference properties correctly', () => {
|
|
462
|
+
const mixedType = {
|
|
463
|
+
id: 'mixed-type',
|
|
464
|
+
typePath: 'item',
|
|
465
|
+
typeProperties: [
|
|
466
|
+
{
|
|
467
|
+
slug: 'name',
|
|
468
|
+
propertyType: types_1.PropertyType.String,
|
|
469
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
slug: 'categoryId',
|
|
473
|
+
propertyType: types_1.PropertyType.ObjectReference,
|
|
474
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
475
|
+
referencedTypePath: 'custom-entity:category',
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
slug: 'isActive',
|
|
479
|
+
propertyType: types_1.PropertyType.Boolean,
|
|
480
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
slug: 'supplierId',
|
|
484
|
+
propertyType: types_1.PropertyType.ObjectReference,
|
|
485
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
486
|
+
referencedTypePath: 'custom-entity:supplier',
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
slug: 'typeRef',
|
|
490
|
+
propertyType: types_1.PropertyType.TypeReference,
|
|
491
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
492
|
+
referencedTypePath: 'custom-entity:type',
|
|
493
|
+
},
|
|
494
|
+
],
|
|
495
|
+
};
|
|
496
|
+
const referencedPaths = (0, create_1.getReferencedObjectPaths)(mixedType);
|
|
497
|
+
expect(referencedPaths).toEqual(['custom-entity:category', 'custom-entity:supplier']);
|
|
498
|
+
expect(referencedPaths).not.toContain('custom-entity:type'); // TypeReference should not be included
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
describe('Property level and role matching edge cases', () => {
|
|
502
|
+
it('should handle valid roles correctly', () => {
|
|
503
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OPTION, 'option')).toBe(true);
|
|
504
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.FAMILY, 'family')).toBe(true);
|
|
505
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.ALL, 'option')).toBe(true);
|
|
506
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.ALL, 'family')).toBe(true);
|
|
507
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OVERRIDABLE, 'option')).toBe(true);
|
|
508
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OVERRIDABLE, 'family')).toBe(true);
|
|
509
|
+
});
|
|
510
|
+
it('should reject mismatched property levels and roles', () => {
|
|
511
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.OPTION, 'family')).toBe(false);
|
|
512
|
+
expect((0, create_1.doesPropertyLevelMatchRole)(types_1.PropertyLevel.FAMILY, 'option')).toBe(false);
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
describe('pickRandomPropertyValues', () => {
|
|
518
|
+
const caches = [new Map(), new Map()];
|
|
519
|
+
const typeWith = (properties) => ({ typePath: 't', typeProperties: properties });
|
|
520
|
+
const familyOnly = {
|
|
521
|
+
slug: 'familyText',
|
|
522
|
+
propertyType: types_1.PropertyType.String,
|
|
523
|
+
propertyLevel: types_1.PropertyLevel.FAMILY,
|
|
524
|
+
};
|
|
525
|
+
const optionOnly = {
|
|
526
|
+
slug: 'optionText',
|
|
527
|
+
propertyType: types_1.PropertyType.String,
|
|
528
|
+
propertyLevel: types_1.PropertyLevel.OPTION,
|
|
529
|
+
};
|
|
530
|
+
const unsupported = {
|
|
531
|
+
slug: 'users',
|
|
532
|
+
propertyType: types_1.PropertyType.UserList,
|
|
533
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
534
|
+
};
|
|
535
|
+
it('should generate only the properties matching the given roles', () => {
|
|
536
|
+
const type = typeWith([familyOnly, optionOnly]);
|
|
537
|
+
const family = (0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], ['family']);
|
|
538
|
+
const option = (0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], ['option']);
|
|
539
|
+
expect(Object.keys(family)).toEqual(['familyText']);
|
|
540
|
+
expect(Object.keys(option)).toEqual(['optionText']);
|
|
541
|
+
});
|
|
542
|
+
it('should skip properties the caller already supplied', () => {
|
|
543
|
+
const type = typeWith([familyOnly, optionOnly]);
|
|
544
|
+
const result = (0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], undefined, new Set(['familyText']));
|
|
545
|
+
expect(Object.keys(result)).toEqual(['optionText']);
|
|
546
|
+
});
|
|
547
|
+
it('should not fail on an unsupported property type when its value was supplied', () => {
|
|
548
|
+
const type = typeWith([unsupported]);
|
|
549
|
+
expect(() => (0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1])).toThrow('Cannot handle property type: userList');
|
|
550
|
+
expect((0, create_1.pickRandomPropertyValues)(type, caches[0], caches[1], undefined, new Set(['users']))).toEqual({});
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
describe('MultiSelect generation', () => {
|
|
554
|
+
const caches = [new Map(), new Map()];
|
|
555
|
+
const options = ['na', 'active', 'big', 'classic', 'custom', 'pro'].map((value) => ({ value }));
|
|
556
|
+
it('should pick a real subset rather than every option', () => {
|
|
557
|
+
const property = {
|
|
558
|
+
slug: 'tags',
|
|
559
|
+
propertyType: types_1.PropertyType.MultiSelect,
|
|
560
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
561
|
+
options,
|
|
562
|
+
};
|
|
563
|
+
const counts = new Set(Array.from({ length: 40 }, () => (0, create_1.pickRandomValueForProperty)(property, caches[0], caches[1]).length));
|
|
564
|
+
expect(Math.max(...counts)).toBeLessThanOrEqual(options.length);
|
|
565
|
+
expect(Math.min(...counts)).toBeGreaterThan(0);
|
|
566
|
+
expect(counts.size).toBeGreaterThan(1);
|
|
567
|
+
});
|
|
568
|
+
it('should not reorder the option list it was given', () => {
|
|
569
|
+
const property = {
|
|
570
|
+
slug: 'tags',
|
|
571
|
+
propertyType: types_1.PropertyType.MultiSelect,
|
|
572
|
+
propertyLevel: types_1.PropertyLevel.ALL,
|
|
573
|
+
options,
|
|
574
|
+
};
|
|
575
|
+
const before = options.map((option) => option.value);
|
|
576
|
+
for (let i = 0; i < 20; i++) {
|
|
577
|
+
(0, create_1.pickRandomValueForProperty)(property, caches[0], caches[1]);
|
|
578
|
+
}
|
|
579
|
+
expect(options.map((option) => option.value)).toEqual(before);
|
|
580
|
+
});
|
|
581
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseCommand } from '../../basecommand';
|
|
2
|
+
export default class DeleteEntity extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
dryRun: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
inputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
+
suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
+
apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
+
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
+
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
static args: {
|
|
14
|
+
entityName: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
15
|
+
ids: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
|
|
16
|
+
};
|
|
17
|
+
static strict: boolean;
|
|
18
|
+
init(): Promise<void>;
|
|
19
|
+
run(): Promise<void>;
|
|
20
|
+
}
|