@softwear/latestcollectioncore 1.0.49 → 1.0.50

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.
@@ -12,7 +12,7 @@ const mappingPairs = [
12
12
  { category: 'Collection', from: 'collectionSupplier', to: 'collection' },
13
13
  { category: 'CustomSize', from: 'sizeSupplier', to: '_customsize' },
14
14
  { category: 'Size', from: 'sizeSupplier', to: 'size' },
15
- { category: 'Gender', from: 'NOFROMFIELD', to: '_gender' },
15
+ { category: 'Gender', from: 'articleGroupSupplier', to: '_gender' },
16
16
  ];
17
17
  function default_1(brands, strategy) {
18
18
  // Helper function to convert all mapping rules for given category to an indexed object
@@ -75,15 +75,13 @@ function default_1(brands, strategy) {
75
75
  const brand = sku.BRANDHASH || (0, index_1.hashBrand)(sku.brand);
76
76
  const mapping = indexedByBrandPropertyMapping[brand];
77
77
  mappingPairs.forEach((pair) => {
78
- var _a, _b;
78
+ var _a, _b, _c, _d, _e;
79
79
  if (sku[pair.to])
80
80
  return; // Do not replace sku-level-user-supplied values
81
- const from = sku[pair.from] || ''; // || "" allows mapping 'from nothing'. Useful to assign constants like Gender for single-gender-brands
82
- let activeMapping = mapping;
83
- const redirectedMapping = (_a = activeMapping === null || activeMapping === void 0 ? void 0 : activeMapping[pair.category]) === null || _a === void 0 ? void 0 : _a['~~'];
84
- if (redirectedMapping)
85
- activeMapping = indexedByBrandPropertyMapping[redirectedMapping];
86
- const to = (_b = activeMapping === null || activeMapping === void 0 ? void 0 : activeMapping[pair.category]) === null || _b === void 0 ? void 0 : _b[from];
81
+ const from = sku[pair.from];
82
+ const redirectedMappingSource = (_a = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _a === void 0 ? void 0 : _a['~~'];
83
+ const redirectedMapping = redirectedMappingSource ? indexedByBrandPropertyMapping[redirectedMappingSource] : {};
84
+ const to = ((_b = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _b === void 0 ? void 0 : _b[from]) || ((_c = mapping === null || mapping === void 0 ? void 0 : mapping[pair.category]) === null || _c === void 0 ? void 0 : _c['']) || ((_d = redirectedMapping === null || redirectedMapping === void 0 ? void 0 : redirectedMapping[pair.category]) === null || _d === void 0 ? void 0 : _d[from]) || ((_e = redirectedMapping === null || redirectedMapping === void 0 ? void 0 : redirectedMapping[pair.category]) === null || _e === void 0 ? void 0 : _e['']);
87
85
  if (!from && !to)
88
86
  return;
89
87
  sku[pair.to] = to ? to : from;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.49",
3
+ "version": "1.0.50",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@ const mappingPairs = [
11
11
  { category: 'Collection', from: 'collectionSupplier', to: 'collection' },
12
12
  { category: 'CustomSize', from: 'sizeSupplier', to: '_customsize' },
13
13
  { category: 'Size', from: 'sizeSupplier', to: 'size' },
14
- { category: 'Gender', from: 'NOFROMFIELD', to: '_gender' },
14
+ { category: 'Gender', from: 'articleGroupSupplier', to: '_gender' },
15
15
  ]
16
16
  export default function (brands: Array<BrandSettingI>, strategy: mappingStrategyE): (sku: SkuI) => SkuI {
17
17
  // Helper function to convert all mapping rules for given category to an indexed object
@@ -68,12 +68,11 @@ export default function (brands: Array<BrandSettingI>, strategy: mappingStrategy
68
68
  const mapping = indexedByBrandPropertyMapping[brand]
69
69
  mappingPairs.forEach((pair) => {
70
70
  if (sku[pair.to]) return // Do not replace sku-level-user-supplied values
71
- const from = sku[pair.from] || '' // || "" allows mapping 'from nothing'. Useful to assign constants like Gender for single-gender-brands
72
- let activeMapping = mapping
73
- const redirectedMapping = activeMapping?.[pair.category]?.['~~']
74
- if (redirectedMapping) activeMapping = indexedByBrandPropertyMapping[redirectedMapping]
71
+ const from = sku[pair.from]
72
+ const redirectedMappingSource = mapping?.[pair.category]?.['~~']
73
+ const redirectedMapping = redirectedMappingSource ? indexedByBrandPropertyMapping[redirectedMappingSource] : {}
75
74
 
76
- const to = activeMapping?.[pair.category]?.[from]
75
+ const to = mapping?.[pair.category]?.[from] || mapping?.[pair.category]?.[''] || redirectedMapping?.[pair.category]?.[from] || redirectedMapping?.[pair.category]?.['']
77
76
  if (!from && !to) return
78
77
  sku[pair.to] = to ? to : from
79
78
  })
@@ -169,6 +169,15 @@ const fullMapping = [
169
169
  },
170
170
  ]
171
171
 
172
+ const fallbackMapping = [
173
+ {
174
+ id: 'levis',
175
+ propertyMapping: [
176
+ { category: 'ColorCode', from: '200', to: 'Blauw-fallbackMapping' },
177
+ { category: 'ColorCode', from: '', to: 'fallbackMapping' },
178
+ ],
179
+ },
180
+ ]
172
181
  describe('applyPropertyMapping', () => {
173
182
  it('returns empty array on an empty array', function () {
174
183
  expect(applyPropertyMapping([], []).length).to.equal(0)
@@ -286,6 +295,19 @@ describe('applyPropertyMapping', () => {
286
295
  expect(mappedSkus[7]._gender).to.equal('uni')
287
296
  })
288
297
 
298
+ it('returns mapped skus on a default mapping rules', function () {
299
+ const mappedSkus = applyPropertyMapping(deepCopy(skus), fallbackMapping)
300
+ expect(mappedSkus[0].colorFamily).to.equal('fallbackMapping')
301
+ expect(mappedSkus[1].colorFamily).to.equal('fallbackMapping')
302
+ expect(mappedSkus[2].colorFamily).to.equal('fallbackMapping')
303
+ expect(mappedSkus[3].colorFamily).to.equal('Blauw-fallbackMapping')
304
+ expect(mappedSkus[4].colorFamily).to.equal('Blauw-fallbackMapping')
305
+ expect(mappedSkus[5].colorFamily).to.equal('Blauw-fallbackMapping')
306
+ expect(mappedSkus[6].colorFamily).to.equal('Blue')
307
+ expect(mappedSkus[7].colorFamily).to.equal('Blue')
308
+ expect(mappedSkus[8].colorFamily).to.equal('Blue')
309
+ })
310
+
289
311
  it('returns cleaned-up redunddant properies on a full mapping', function () {
290
312
  const cleanedSkus = applyPropertyCleaning(deepCopy(skus), fullMapping)
291
313
  expect(cleanedSkus[9].articleGroupSupplier).to.equal('ForTheCleanupTest')