@contrail/cli 3.5.0 → 3.5.1-alpha.64bf880
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 +1 -25
- package/dist/api/types.d.ts +0 -5
- package/dist/api/types.js +1 -36
- package/dist/commands/types/getAll.js +0 -18
- package/dist/commands/types/loadAll.js +0 -2
- package/dist/commands/types/mergeTypeProperties.js +0 -5
- package/dist/commands/types/uploadOptionSetHierarchies.js +0 -117
- package/dist/commands/types/uploadOptionSets.js +1 -1
- package/dist/commands/types/uploadRuleSets.js +2 -85
- package/dist/commands/types/uploadTypeOverrides.js +10 -2
- package/dist/commands/types/uploadTypePolicies.js +2 -86
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +0 -1
- package/dist/commands/types/uploadTypePropertyPolicies.js +3 -139
- package/dist/helpers/types/type-uploader.js +1 -1
- package/dist/interfaces.d.ts +0 -25
- package/dist/templates/typescript/tsup.config.ts +0 -0
- package/node_modules/@contrail/loader/lib/color-processor.js +9 -23
- package/node_modules/@contrail/loader/lib/color-processor.spec.js +112 -62
- package/node_modules/@contrail/loader/lib/common/chunk-by-url-length.d.ts +1 -1
- package/node_modules/@contrail/loader/lib/common/chunk-by-url-length.js +2 -0
- package/node_modules/@contrail/loader/lib/common/chunk-by-url-length.spec.js +4 -0
- package/node_modules/@contrail/loader/lib/common/color-validation.d.ts +26 -0
- package/node_modules/@contrail/loader/lib/common/color-validation.js +163 -0
- package/node_modules/@contrail/loader/lib/common/color-validation.spec.js +102 -0
- package/node_modules/@contrail/loader/lib/common/size-range-helpers.js +0 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +0 -3
- package/node_modules/@contrail/loader/lib/constants.js +1 -4
- package/node_modules/@contrail/loader/lib/entities-v2/colors-v2/color-processor-v2.js +9 -23
- package/node_modules/@contrail/loader/lib/entities-v2/colors-v2/color-processor-v2.spec.js +112 -62
- package/node_modules/@contrail/loader/lib/entities-v2/entities-helper.js +0 -1
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/assortment-processor.js +0 -1
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +8 -22
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +43 -1
- package/node_modules/@contrail/loader/lib/pipeline/identifier-resolver.d.ts +5 -0
- package/node_modules/@contrail/loader/lib/pipeline/identifier-resolver.js +562 -0
- package/node_modules/@contrail/loader/lib/pipeline/identifier-resolver.spec.d.ts +1 -0
- package/node_modules/@contrail/loader/lib/pipeline/identifier-resolver.spec.js +231 -0
- package/node_modules/@contrail/loader/lib/pipeline/item-execute-helpers.js +77 -3
- package/node_modules/@contrail/loader/lib/pipeline/item-execute-helpers.spec.js +82 -0
- package/node_modules/@contrail/loader/lib/pipeline/preview.js +0 -5
- package/node_modules/@contrail/loader/lib/pipeline/preview.spec.js +2 -2
- package/node_modules/@contrail/loader/lib/pipeline/project-item-execute-helpers.js +1 -1
- package/node_modules/@contrail/loader/lib/pipeline/transform.js +18 -0
- package/node_modules/@contrail/loader/lib/pipeline/transform.spec.js +3 -2
- package/node_modules/@contrail/loader/lib/pipeline/types.d.ts +5 -2
- package/node_modules/@contrail/loader/lib/pipeline/types.js +2 -0
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +184 -437
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +157 -53
- package/node_modules/@contrail/loader/package.json +3 -2
- package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +120 -0
- package/node_modules/@contrail/sdk/lib/auth/login.js +42 -3
- package/node_modules/@contrail/sdk/lib/core/request.d.ts +3 -0
- package/node_modules/@contrail/sdk/lib/core/request.js +100 -4
- package/node_modules/@contrail/sdk/lib/entities/entities.client.js +1 -1
- package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
- package/node_modules/@contrail/sdk/lib/files/files.d.ts +13 -3
- package/node_modules/@contrail/sdk/lib/files/files.js +66 -25
- package/node_modules/@contrail/sdk/package.json +4 -1
- package/node_modules/validate-color/LICENSE +21 -0
- package/node_modules/validate-color/README.md +265 -0
- package/node_modules/validate-color/lib/index.d.ts +10 -0
- package/node_modules/validate-color/lib/index.js +1 -0
- package/node_modules/validate-color/package.json +91 -0
- package/node_modules/validate-color/test/redos.js +29 -0
- package/oclif.manifest.json +1 -52
- package/package.json +3 -3
- package/dist/commands/types/uploadUsageInfo.d.ts +0 -15
- package/dist/commands/types/uploadUsageInfo.js +0 -180
- package/dist/commands/types/uploadUsageInfo.spec.js +0 -249
- /package/{dist/commands/types/uploadUsageInfo.spec.d.ts → node_modules/@contrail/loader/lib/common/color-validation.spec.d.ts} +0 -0
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformReducedUsageInfoToTypeIdsFromPath = exports.persistReducedUsageInfoFields = exports.uploadUsageInfo = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const sdk_1 = require("@contrail/sdk");
|
|
6
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
-
const login_1 = require("../../auth/login");
|
|
8
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
-
const path = tslib_1.__importStar(require("path"));
|
|
10
|
-
const core_1 = require("@oclif/core");
|
|
11
|
-
const type_extractor_1 = require("../../helpers/types/type-extractor");
|
|
12
|
-
const basecommand_1 = require("../../basecommand");
|
|
13
|
-
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
14
|
-
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
15
|
-
class UploadUsageInfo extends basecommand_1.BaseCommand {
|
|
16
|
-
static description = 'Upload extracted usage info';
|
|
17
|
-
static examples = [
|
|
18
|
-
`$ contrail types uploadUsageInfo
|
|
19
|
-
`,
|
|
20
|
-
];
|
|
21
|
-
static flags = {
|
|
22
|
-
...basecommand_1.BaseCommand.baseFlags,
|
|
23
|
-
dir: core_1.Flags.string({
|
|
24
|
-
char: 'd',
|
|
25
|
-
description: 'The directory from which to export the usage info data. Defaults to the current directory. The usage info data will be loaded from $dir/usage-info.yml',
|
|
26
|
-
required: false,
|
|
27
|
-
default: '.',
|
|
28
|
-
}),
|
|
29
|
-
};
|
|
30
|
-
async run() {
|
|
31
|
-
await uploadUsageInfo(this.flags.dir);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.default = UploadUsageInfo;
|
|
35
|
-
async function uploadUsageInfo(dir) {
|
|
36
|
-
try {
|
|
37
|
-
await (0, login_1.authUser)();
|
|
38
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('USAGE INFO')} Uploading`);
|
|
39
|
-
const reducedUsageInfo = await loadUsageInfo(dir);
|
|
40
|
-
await uploadUsageInfoObjects(reducedUsageInfo);
|
|
41
|
-
logger_1.default.info(`${chalk_1.default.yellow.bold('USAGE INFO')} Uploaded`);
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
logger_1.default.info(`${chalk_1.default.red.bold('FAIL')} Usage Info Upload Failed . ${e}`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
logger_1.default.info(`${chalk_1.default.green.bold('COMPLETE')} Usage Info Upload Complete.`);
|
|
48
|
-
}
|
|
49
|
-
exports.uploadUsageInfo = uploadUsageInfo;
|
|
50
|
-
function loadUsageInfo(dir) {
|
|
51
|
-
try {
|
|
52
|
-
const doc = js_yaml_1.default.load(fs_1.default.readFileSync(path.join(dir, 'usage-info.yml'), 'utf8'));
|
|
53
|
-
return doc;
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function uploadUsageInfoObjects(loadedUsageInfo) {
|
|
60
|
-
const typesWithProperties = await (0, type_extractor_1.getTypes)();
|
|
61
|
-
const currentUsageInfo = await new sdk_1.Entities().get({
|
|
62
|
-
entityName: 'type-property-usage-info',
|
|
63
|
-
});
|
|
64
|
-
const currentUsageInfosHashes = {};
|
|
65
|
-
for (const currentUI of currentUsageInfo) {
|
|
66
|
-
const foundType = typesWithProperties.find((t) => t.id === currentUI.typeId);
|
|
67
|
-
const typeProperties = foundType?.typeProperties || [];
|
|
68
|
-
const foundTypeProperty = typeProperties.find((tp) => tp.id === currentUI.typePropertyId);
|
|
69
|
-
if (!foundType || !foundTypeProperty) {
|
|
70
|
-
logger_1.default.info(`skipping unhashable, invalid usage info: ${JSON.stringify(currentUI, null, 2)}`);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
const hash = `${foundType.typePath}|${foundTypeProperty.slug}`;
|
|
74
|
-
currentUsageInfosHashes[hash] = currentUI;
|
|
75
|
-
}
|
|
76
|
-
const reducedUsageInfoHashes = {};
|
|
77
|
-
for (const loadedUI of loadedUsageInfo) {
|
|
78
|
-
const hash = `${loadedUI.typePath}|${loadedUI.typePropertySlug}`;
|
|
79
|
-
reducedUsageInfoHashes[hash] = loadedUI;
|
|
80
|
-
}
|
|
81
|
-
logger_1.default.debug(`current usage info: ${JSON.stringify(currentUsageInfo)}`);
|
|
82
|
-
logger_1.default.debug(`loaded usage info: ${JSON.stringify(loadedUsageInfo)}`);
|
|
83
|
-
for (const loadedUI of loadedUsageInfo) {
|
|
84
|
-
try {
|
|
85
|
-
const found = currentUsageInfosHashes[`${loadedUI.typePath}|${loadedUI.typePropertySlug}`];
|
|
86
|
-
const transformedUI = transformReducedUsageInfoToTypeIdsFromPath(loadedUI, typesWithProperties);
|
|
87
|
-
if (!transformedUI) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (!found) {
|
|
91
|
-
logger_1.default.debug(`Creating: ${JSON.stringify(transformedUI)}`);
|
|
92
|
-
await new sdk_1.Entities().create({
|
|
93
|
-
entityName: 'type-property-usage-info',
|
|
94
|
-
object: transformedUI,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
logger_1.default.info(`Updating: ${JSON.stringify(transformedUI)}`);
|
|
99
|
-
await new sdk_1.Entities().update({
|
|
100
|
-
entityName: 'type-property-usage-info',
|
|
101
|
-
id: found.id,
|
|
102
|
-
object: transformedUI,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
logger_1.default.error(`Error Uploading usage info: ${err}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
for (const [hash, currentUI] of Object.entries(currentUsageInfosHashes)) {
|
|
111
|
-
try {
|
|
112
|
-
const found = reducedUsageInfoHashes[hash];
|
|
113
|
-
if (!found) {
|
|
114
|
-
logger_1.default.debug(`Creating: ${hash}`);
|
|
115
|
-
await new sdk_1.Entities().delete({
|
|
116
|
-
entityName: 'type-property-usage-info',
|
|
117
|
-
id: currentUI['id'],
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
logger_1.default.error(`Error Deleting usage info: ${err}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
//This should contain the property keys in PersistReducedUsageInfo in interfaces.ts
|
|
127
|
-
//except for typePath and typePropertySlug which are used for transformation but not persisted to the database.
|
|
128
|
-
// If you add a new property to PersistReducedUsageInfo, you need to add it to this array to be persisted to the database.
|
|
129
|
-
exports.persistReducedUsageInfoFields = [
|
|
130
|
-
// 'typePath',
|
|
131
|
-
// 'typePropertySlug',
|
|
132
|
-
'typeId',
|
|
133
|
-
'typePropertyId',
|
|
134
|
-
'editable',
|
|
135
|
-
'used',
|
|
136
|
-
'formulaFunction',
|
|
137
|
-
'validationFunction',
|
|
138
|
-
'numberFormat',
|
|
139
|
-
'defaultValue',
|
|
140
|
-
'label',
|
|
141
|
-
'required',
|
|
142
|
-
'searchable',
|
|
143
|
-
'isUniqueProperty',
|
|
144
|
-
'isUniquePropertyInFamily',
|
|
145
|
-
'copyBehavior',
|
|
146
|
-
'copyDefault',
|
|
147
|
-
'propertyLevel',
|
|
148
|
-
'isArchived',
|
|
149
|
-
'isFederationProperty',
|
|
150
|
-
'carryOverBehavior',
|
|
151
|
-
'carryOverDefault',
|
|
152
|
-
];
|
|
153
|
-
// transforms the reduced Usage Info from name slugs to ids
|
|
154
|
-
function transformReducedUsageInfoToTypeIdsFromPath(reducedUsageInfo, types) {
|
|
155
|
-
const foundType = types.find((t) => t.typePath === reducedUsageInfo.typePath);
|
|
156
|
-
if (!foundType) {
|
|
157
|
-
logger_1.default.error(`Could not find type with typePath ${reducedUsageInfo.typePath} while transforming ${reducedUsageInfo.typePropertySlug}`);
|
|
158
|
-
return undefined;
|
|
159
|
-
}
|
|
160
|
-
const foundTypeProperty = foundType.typeProperties?.find((tp) => tp.slug === reducedUsageInfo.typePropertySlug);
|
|
161
|
-
if (!foundTypeProperty) {
|
|
162
|
-
logger_1.default.error(`Could not find type property with slug ${reducedUsageInfo.typePropertySlug} while transforming ${JSON.stringify(reducedUsageInfo)}`);
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
// Create a new object with only the properties that are in the persistReducedUsageInfoFields array
|
|
166
|
-
// If there is a compile error on the code below, it means you added a new property to PersistReducedUsageInfo
|
|
167
|
-
// interface in interfaces.ts but forgot to add it to the persistReducedUsageInfoFields array above,
|
|
168
|
-
// It needs to be added to be persisted to the database.
|
|
169
|
-
const persistedUsageInfo = {
|
|
170
|
-
typeId: foundType.id,
|
|
171
|
-
typePropertyId: foundTypeProperty.id,
|
|
172
|
-
};
|
|
173
|
-
for (const key of Object.keys(reducedUsageInfo)) {
|
|
174
|
-
if (exports.persistReducedUsageInfoFields.includes(key)) {
|
|
175
|
-
persistedUsageInfo[key] = reducedUsageInfo[key];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return persistedUsageInfo;
|
|
179
|
-
}
|
|
180
|
-
exports.transformReducedUsageInfoToTypeIdsFromPath = transformReducedUsageInfoToTypeIdsFromPath;
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const uploadUsageInfo_1 = require("./uploadUsageInfo");
|
|
5
|
-
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
6
|
-
// Mock the logger
|
|
7
|
-
jest.mock('../../logger', () => ({
|
|
8
|
-
error: jest.fn(),
|
|
9
|
-
info: jest.fn(),
|
|
10
|
-
debug: jest.fn(),
|
|
11
|
-
}));
|
|
12
|
-
describe('transformReducedUsageInfoToTypeIdsFromPath', () => {
|
|
13
|
-
const mockTypes = [
|
|
14
|
-
{
|
|
15
|
-
id: 'type-123',
|
|
16
|
-
typePath: 'product/clothing',
|
|
17
|
-
typeProperties: [
|
|
18
|
-
{
|
|
19
|
-
id: 'prop-456',
|
|
20
|
-
slug: 'color',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: 'prop-789',
|
|
24
|
-
slug: 'size',
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
id: 'type-abc',
|
|
30
|
-
typePath: 'product/electronics',
|
|
31
|
-
typeProperties: [
|
|
32
|
-
{
|
|
33
|
-
id: 'prop-def',
|
|
34
|
-
slug: 'brand',
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
jest.clearAllMocks();
|
|
41
|
-
});
|
|
42
|
-
it('should successfully transform a valid reducedUsageInfo object', () => {
|
|
43
|
-
const reducedUsageInfo = {
|
|
44
|
-
typePath: 'product/clothing',
|
|
45
|
-
typePropertySlug: 'color',
|
|
46
|
-
editable: true,
|
|
47
|
-
used: true,
|
|
48
|
-
label: 'Color',
|
|
49
|
-
extraProperty: 'should be removed',
|
|
50
|
-
};
|
|
51
|
-
const result = (0, uploadUsageInfo_1.transformReducedUsageInfoToTypeIdsFromPath)(reducedUsageInfo, mockTypes);
|
|
52
|
-
expect(result).toBeDefined();
|
|
53
|
-
expect(result.typeId).toBe('type-123');
|
|
54
|
-
expect(result.typePropertyId).toBe('prop-456');
|
|
55
|
-
expect(result.extraProperty).toBeUndefined();
|
|
56
|
-
expect(result.editable).toBe(true);
|
|
57
|
-
expect(result.used).toBe(true);
|
|
58
|
-
expect(result.label).toBe('Color');
|
|
59
|
-
// Verify original object is not mutated
|
|
60
|
-
expect(reducedUsageInfo.typeId).toBeUndefined();
|
|
61
|
-
expect(reducedUsageInfo.typePropertyId).toBeUndefined();
|
|
62
|
-
});
|
|
63
|
-
it('should return undefined when type is not found', () => {
|
|
64
|
-
const reducedUsageInfo = {
|
|
65
|
-
typePath: 'product/nonexistent',
|
|
66
|
-
typePropertySlug: 'color',
|
|
67
|
-
editable: true,
|
|
68
|
-
};
|
|
69
|
-
const result = (0, uploadUsageInfo_1.transformReducedUsageInfoToTypeIdsFromPath)(reducedUsageInfo, mockTypes);
|
|
70
|
-
expect(result).toBeUndefined();
|
|
71
|
-
expect(logger_1.default.error).toHaveBeenCalledWith(expect.stringContaining('Could not find type with typePath product/nonexistent'));
|
|
72
|
-
// Verify original object is not mutated
|
|
73
|
-
expect(reducedUsageInfo.typeId).toBeUndefined();
|
|
74
|
-
expect(reducedUsageInfo.typePropertyId).toBeUndefined();
|
|
75
|
-
});
|
|
76
|
-
it('should return undefined when type property is not found', () => {
|
|
77
|
-
const reducedUsageInfo = {
|
|
78
|
-
typePath: 'product/clothing',
|
|
79
|
-
typePropertySlug: 'nonexistent-property',
|
|
80
|
-
editable: true,
|
|
81
|
-
};
|
|
82
|
-
const result = (0, uploadUsageInfo_1.transformReducedUsageInfoToTypeIdsFromPath)(reducedUsageInfo, mockTypes);
|
|
83
|
-
expect(result).toBeUndefined();
|
|
84
|
-
expect(logger_1.default.error).toHaveBeenCalledWith(expect.stringContaining('Could not find type property with slug nonexistent-property'));
|
|
85
|
-
// Verify original object is not mutated
|
|
86
|
-
expect(reducedUsageInfo.typeId).toBeUndefined();
|
|
87
|
-
expect(reducedUsageInfo.typePropertyId).toBeUndefined();
|
|
88
|
-
});
|
|
89
|
-
it('should exclude properties not in persistReducedUsageInfoFields', () => {
|
|
90
|
-
const reducedUsageInfo = {
|
|
91
|
-
typePath: 'product/clothing',
|
|
92
|
-
typePropertySlug: 'color',
|
|
93
|
-
editable: true,
|
|
94
|
-
used: false,
|
|
95
|
-
formulaFunction: 'someFormula',
|
|
96
|
-
extraField1: 'value1',
|
|
97
|
-
extraField2: 'value2',
|
|
98
|
-
randomProperty: 123,
|
|
99
|
-
};
|
|
100
|
-
const result = (0, uploadUsageInfo_1.transformReducedUsageInfoToTypeIdsFromPath)(reducedUsageInfo, mockTypes);
|
|
101
|
-
expect(result).toBeDefined();
|
|
102
|
-
expect(result.extraField1).toBeUndefined();
|
|
103
|
-
expect(result.extraField2).toBeUndefined();
|
|
104
|
-
expect(result.randomProperty).toBeUndefined();
|
|
105
|
-
expect(result.editable).toBeDefined();
|
|
106
|
-
expect(result.used).toBeDefined();
|
|
107
|
-
expect(result.formulaFunction).toBeDefined();
|
|
108
|
-
});
|
|
109
|
-
it('should preserve all valid persistReducedUsageInfoFields', () => {
|
|
110
|
-
const reducedUsageInfo = {
|
|
111
|
-
typePath: 'product/electronics',
|
|
112
|
-
typePropertySlug: 'brand',
|
|
113
|
-
editable: true,
|
|
114
|
-
used: true,
|
|
115
|
-
formulaFunction: 'formula',
|
|
116
|
-
validationFunction: 'validation',
|
|
117
|
-
numberFormat: '0.00',
|
|
118
|
-
defaultValue: 'default',
|
|
119
|
-
label: 'Brand',
|
|
120
|
-
required: true,
|
|
121
|
-
searchable: true,
|
|
122
|
-
isUniqueProperty: false,
|
|
123
|
-
isUniquePropertyInFamily: false,
|
|
124
|
-
copyBehavior: 'copy',
|
|
125
|
-
copyDefault: true,
|
|
126
|
-
propertyLevel: 'instance',
|
|
127
|
-
isArchived: false,
|
|
128
|
-
shouldBeRemoved: 'extra',
|
|
129
|
-
isFederationProperty: false,
|
|
130
|
-
carryOverBehavior: 'carry',
|
|
131
|
-
carryOverDefault: 'default',
|
|
132
|
-
};
|
|
133
|
-
const result = (0, uploadUsageInfo_1.transformReducedUsageInfoToTypeIdsFromPath)(reducedUsageInfo, mockTypes);
|
|
134
|
-
expect(result).toBeDefined();
|
|
135
|
-
expect(result.typeId).toBe('type-abc');
|
|
136
|
-
expect(result.typePropertyId).toBe('prop-def');
|
|
137
|
-
expect(result.shouldBeRemoved).toBeUndefined();
|
|
138
|
-
// Verify all valid fields are preserved
|
|
139
|
-
uploadUsageInfo_1.persistReducedUsageInfoFields.forEach((field) => {
|
|
140
|
-
expect(result[field]).toBeDefined();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
it('should return undefined for empty types array', () => {
|
|
144
|
-
const reducedUsageInfo = {
|
|
145
|
-
typePath: 'product/clothing',
|
|
146
|
-
typePropertySlug: 'color',
|
|
147
|
-
editable: true,
|
|
148
|
-
};
|
|
149
|
-
const result = (0, uploadUsageInfo_1.transformReducedUsageInfoToTypeIdsFromPath)(reducedUsageInfo, []);
|
|
150
|
-
expect(result).toBeUndefined();
|
|
151
|
-
expect(logger_1.default.error).toHaveBeenCalled();
|
|
152
|
-
});
|
|
153
|
-
it('should return undefined for type with empty typeProperties array', () => {
|
|
154
|
-
const typesWithEmptyProps = [
|
|
155
|
-
{
|
|
156
|
-
id: 'type-123',
|
|
157
|
-
typePath: 'product/clothing',
|
|
158
|
-
typeProperties: [],
|
|
159
|
-
},
|
|
160
|
-
];
|
|
161
|
-
const reducedUsageInfo = {
|
|
162
|
-
typePath: 'product/clothing',
|
|
163
|
-
typePropertySlug: 'color',
|
|
164
|
-
editable: true,
|
|
165
|
-
};
|
|
166
|
-
const result = (0, uploadUsageInfo_1.transformReducedUsageInfoToTypeIdsFromPath)(reducedUsageInfo, typesWithEmptyProps);
|
|
167
|
-
expect(result).toBeUndefined();
|
|
168
|
-
expect(logger_1.default.error).toHaveBeenCalledWith(expect.stringContaining('Could not find type property with slug color'));
|
|
169
|
-
});
|
|
170
|
-
it('should not mutate the original object', () => {
|
|
171
|
-
const reducedUsageInfo = {
|
|
172
|
-
typePath: 'product/clothing',
|
|
173
|
-
typePropertySlug: 'size',
|
|
174
|
-
editable: false,
|
|
175
|
-
extraProp: 'remove',
|
|
176
|
-
};
|
|
177
|
-
const originalRef = reducedUsageInfo;
|
|
178
|
-
const result = (0, uploadUsageInfo_1.transformReducedUsageInfoToTypeIdsFromPath)(reducedUsageInfo, mockTypes);
|
|
179
|
-
// Verify the original object is not mutated
|
|
180
|
-
expect(reducedUsageInfo).toBe(originalRef);
|
|
181
|
-
expect(reducedUsageInfo.typeId).toBeUndefined();
|
|
182
|
-
expect(reducedUsageInfo.typePropertyId).toBeUndefined();
|
|
183
|
-
expect(reducedUsageInfo.extraProp).toBe('remove');
|
|
184
|
-
// Verify result is a new object with correct data
|
|
185
|
-
expect(result).toBeDefined();
|
|
186
|
-
expect(result.typeId).toBe('type-123');
|
|
187
|
-
expect(result.typePropertyId).toBe('prop-789');
|
|
188
|
-
expect(result.extraProp).toBeUndefined();
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
describe('persistReducedUsageInfoFields validation', () => {
|
|
192
|
-
it('should contain all properties from PersistReducedUsageInfo interface', () => {
|
|
193
|
-
// Create a sample object with all required properties from PersistReducedUsageInfo
|
|
194
|
-
// This will fail at compile time if we're missing any properties
|
|
195
|
-
const samplePersistReducedUsageInfo = {
|
|
196
|
-
typeId: 'type-123',
|
|
197
|
-
typePropertyId: 'prop-456',
|
|
198
|
-
editable: true,
|
|
199
|
-
used: true,
|
|
200
|
-
formulaFunction: 'formula',
|
|
201
|
-
validationFunction: 'validation',
|
|
202
|
-
numberFormat: '0.00',
|
|
203
|
-
defaultValue: 'default',
|
|
204
|
-
label: 'Label',
|
|
205
|
-
required: true,
|
|
206
|
-
searchable: true,
|
|
207
|
-
isUniqueProperty: false,
|
|
208
|
-
isUniquePropertyInFamily: false,
|
|
209
|
-
copyBehavior: 'copy',
|
|
210
|
-
copyDefault: 'default',
|
|
211
|
-
propertyLevel: 'instance',
|
|
212
|
-
isArchived: false,
|
|
213
|
-
isFederationProperty: false,
|
|
214
|
-
carryOverBehavior: 'carry',
|
|
215
|
-
carryOverDefault: 'default',
|
|
216
|
-
};
|
|
217
|
-
// Get all keys from the sample object
|
|
218
|
-
const allKeys = Object.keys(samplePersistReducedUsageInfo);
|
|
219
|
-
// Verify that every key exists in persistReducedUsageInfoFields
|
|
220
|
-
const missingKeys = [];
|
|
221
|
-
allKeys.forEach((key) => {
|
|
222
|
-
if (!uploadUsageInfo_1.persistReducedUsageInfoFields.includes(key)) {
|
|
223
|
-
missingKeys.push(key);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
// This test will fail if any keys are missing
|
|
227
|
-
expect(missingKeys).toEqual([]);
|
|
228
|
-
expect(missingKeys.length).toBe(0);
|
|
229
|
-
});
|
|
230
|
-
it('should contain only valid properties from PersistReducedUsageInfo interface', () => {
|
|
231
|
-
// Verify no extra keys that don't exist in the interface
|
|
232
|
-
// This is more of a documentation test - TypeScript already enforces this at compile time
|
|
233
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
234
|
-
const samplePersistReducedUsageInfo = {
|
|
235
|
-
typeId: 'type-123',
|
|
236
|
-
typePropertyId: 'prop-456',
|
|
237
|
-
editable: true,
|
|
238
|
-
used: true,
|
|
239
|
-
isArchived: false,
|
|
240
|
-
};
|
|
241
|
-
// Every field in the array should be a valid key
|
|
242
|
-
uploadUsageInfo_1.persistReducedUsageInfoFields.forEach((field) => {
|
|
243
|
-
// TypeScript ensures this at compile time, but we can document it in tests
|
|
244
|
-
expect(typeof field).toBe('string');
|
|
245
|
-
// Also verify the field could exist in the sample
|
|
246
|
-
expect(field).toBeTruthy();
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
});
|