@softwear/latestcollectioncore 1.0.13 → 1.0.15

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.
@@ -1 +1 @@
1
- export default function (skus: any, activeConfig: any, metaBrandSetting: any, dataProviderBrandSetting: any, tenantBrandSetting: any): void;
1
+ export default function (skus: any, activeConfig: any, metaBrandSetting: any, dataProviderBrandSetting: any, tenantBrandSetting: any): any;
@@ -2,12 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_1 = require("./index");
4
4
  function default_1(skus, activeConfig, metaBrandSetting, dataProviderBrandSetting, tenantBrandSetting) {
5
+ let allMappings = [];
5
6
  if (activeConfig?.products?.applyLatestCollectionMapping?.value)
6
- (0, index_1.applyPropertyMapping)(skus, metaBrandSetting);
7
- activeConfig?.products?.applyDataProviderMapping?.value.forEach((provider) => {
8
- (0, index_1.applyPropertyMapping)(skus, dataProviderBrandSetting.filter((s) => s.dataProvider == provider).map((s) => ({ ...s, id: s.id.split(":")[0] })));
9
- });
7
+ allMappings = metaBrandSetting;
8
+ if (activeConfig?.products?.applyDataProviderMapping?.value)
9
+ activeConfig.products.applyDataProviderMapping.value.forEach((provider) => {
10
+ allMappings = allMappings.concat(dataProviderBrandSetting.filter((s) => s.dataProvider == provider).map((s) => ({ ...s, id: s.id.split(":")[0] })));
11
+ });
10
12
  if (activeConfig?.products?.applyTenantMapping?.value)
11
- (0, index_1.applyPropertyMapping)(skus, tenantBrandSetting);
13
+ allMappings = allMappings.concat(tenantBrandSetting);
14
+ (0, index_1.applyPropertyMapping)(skus, allMappings);
15
+ return skus;
12
16
  }
13
17
  exports.default = default_1;
@@ -25,7 +25,9 @@ function default_1(skus, brands) {
25
25
  return maps;
26
26
  };
27
27
  const indexedPropertyMapping = brands.reduce((acc, item) => {
28
- acc[item.id] = indexFn(item.propertyMapping);
28
+ if (!acc[item.id])
29
+ acc[item.id] = {};
30
+ acc[item.id] = { ...acc[item.id], ...indexFn(item.propertyMapping) };
29
31
  return acc;
30
32
  }, {});
31
33
  return skus.map((sku) => {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc -p tsconfig.json",
9
- "test": "mocha"
9
+ "test": "mocha --reporter spec --full-trace"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -1,14 +1,14 @@
1
1
  import { applyPropertyMapping } from "./index"
2
2
 
3
3
  export default function (skus, activeConfig, metaBrandSetting, dataProviderBrandSetting, tenantBrandSetting) {
4
- if (activeConfig?.products?.applyLatestCollectionMapping?.value) applyPropertyMapping(skus, metaBrandSetting)
4
+ let allMappings = []
5
+ if (activeConfig?.products?.applyLatestCollectionMapping?.value) allMappings = metaBrandSetting
6
+ if (activeConfig?.products?.applyDataProviderMapping?.value)
7
+ activeConfig.products.applyDataProviderMapping.value.forEach((provider) => {
8
+ allMappings = allMappings.concat(dataProviderBrandSetting.filter((s) => s.dataProvider == provider).map((s) => ({ ...s, id: s.id.split(":")[0] })))
9
+ })
5
10
 
6
- activeConfig?.products?.applyDataProviderMapping?.value.forEach((provider) => {
7
- applyPropertyMapping(
8
- skus,
9
- dataProviderBrandSetting.filter((s) => s.dataProvider == provider).map((s) => ({ ...s, id: s.id.split(":")[0] }))
10
- )
11
- })
12
-
13
- if (activeConfig?.products?.applyTenantMapping?.value) applyPropertyMapping(skus, tenantBrandSetting)
11
+ if (activeConfig?.products?.applyTenantMapping?.value) allMappings = allMappings.concat(tenantBrandSetting)
12
+ applyPropertyMapping(skus, allMappings)
13
+ return skus
14
14
  }
@@ -22,7 +22,8 @@ export default function (skus: Array<SkuI>, brands: Array<any>): any {
22
22
  return maps
23
23
  }
24
24
  const indexedPropertyMapping = brands.reduce((acc, item) => {
25
- acc[item.id] = indexFn(item.propertyMapping)
25
+ if (!acc[item.id]) acc[item.id] = {}
26
+ acc[item.id] = { ...acc[item.id], ...indexFn(item.propertyMapping) }
26
27
  return acc
27
28
  }, {})
28
29
  return skus.map((sku: SkuI) => {
@@ -0,0 +1,245 @@
1
+ const { deepCopy, applyPreferedPropertyMappings } = require("../dist/index")
2
+ const { expect } = require("chai")
3
+
4
+ const skus = [
5
+ {
6
+ id: "1234567890128",
7
+ brand: "levis",
8
+ collection: "22summer",
9
+ collectionSupplier: "SUMMER 2022",
10
+ colorCodeSupplier: "100",
11
+ colorFamily: "White",
12
+ size: "S",
13
+ },
14
+ {
15
+ id: "1234567890129",
16
+ brand: "levis",
17
+ collection: "22summer",
18
+ collectionSupplier: "SUMMER 2022",
19
+ colorCodeSupplier: "100",
20
+ colorFamily: "White",
21
+ size: "M",
22
+ },
23
+ {
24
+ id: "1234567890130",
25
+ brand: "levis",
26
+ collection: "22summer",
27
+ collectionSupplier: "SUMMER 2022",
28
+ colorCodeSupplier: "100",
29
+ colorFamily: "White",
30
+ size: "L",
31
+ },
32
+ {
33
+ id: "1234567890131",
34
+ brand: "levis",
35
+ collection: "22summer",
36
+ collectionSupplier: "SUMMER 2022",
37
+ colorCodeSupplier: "200",
38
+ colorFamily: "Blue",
39
+ size: "S",
40
+ },
41
+ {
42
+ id: "1234567890132",
43
+ brand: "levis",
44
+ collection: "22summer",
45
+ collectionSupplier: "SUMMER 2022",
46
+ colorCodeSupplier: "200",
47
+ colorFamily: "Blue",
48
+ size: "M",
49
+ },
50
+ {
51
+ id: "1234567890133",
52
+ brand: "levis",
53
+ collection: "22summer",
54
+ collectionSupplier: "SUMMER 2022",
55
+ colorCodeSupplier: "200",
56
+ colorFamily: "Blue",
57
+ size: "L",
58
+ },
59
+ {
60
+ id: "1234567890134",
61
+ brand: "gstar",
62
+ collection: "22summer",
63
+ collectionSupplier: "SUMMER 2022",
64
+ colorCodeSupplier: "200",
65
+ colorFamily: "Blue",
66
+ size: "S",
67
+ },
68
+ {
69
+ id: "1234567890135",
70
+ brand: "gstar",
71
+ collection: "22summer",
72
+ collectionSupplier: "SUMMER 2022",
73
+ colorCodeSupplier: "200",
74
+ colorFamily: "Blue",
75
+ size: "M",
76
+ },
77
+ {
78
+ id: "1234567890136",
79
+ brand: "gstar",
80
+ collection: "22summer",
81
+ collectionSupplier: "SUMMER 2022",
82
+ colorCodeSupplier: "200",
83
+ colorFamily: "Blue",
84
+ size: "L",
85
+ },
86
+ ]
87
+
88
+ const metaDataMapping = [
89
+ {
90
+ id: "levis",
91
+ propertyMapping: [
92
+ { category: "ColorCode", from: "200", to: "Blauw" },
93
+ { category: "ColorCode", from: "100", to: "Wit" },
94
+ ],
95
+ },
96
+ ]
97
+
98
+ const dataProviderMapping = [
99
+ {
100
+ id: "levis:linolux",
101
+ dataProvider: "linolux",
102
+ propertyMapping: [
103
+ { category: "ColorCode", from: "200", to: "Blauwer" },
104
+ { category: "ColorCode", from: "100", to: "Witter" },
105
+ { category: "Collection", from: "SUMMER 2022", to: "22zomer" },
106
+ ],
107
+ },
108
+ ]
109
+
110
+ const tenantMapping = [
111
+ {
112
+ id: "levis",
113
+ propertyMapping: [{ category: "Collection", from: "SUMMER 2022", to: "22zomer" }],
114
+ },
115
+ {
116
+ id: "gstar",
117
+ propertyMapping: [{ category: "Collection", from: "SUMMER 2022", to: "22zomer" }],
118
+ },
119
+ ]
120
+
121
+ const oneMappingActive = {
122
+ products: {
123
+ applyLatestCollectionMapping: {
124
+ value: true,
125
+ },
126
+ applyTenantMapping: {
127
+ value: false,
128
+ },
129
+ applyDataProviderMapping: {
130
+ value: [],
131
+ },
132
+ },
133
+ }
134
+
135
+ const twoMappingsActive = {
136
+ products: {
137
+ applyLatestCollectionMapping: {
138
+ value: true,
139
+ },
140
+ applyTenantMapping: {
141
+ value: false,
142
+ },
143
+ applyDataProviderMapping: {
144
+ value: ["linolux"],
145
+ },
146
+ },
147
+ }
148
+ const allMappingsActive = {
149
+ products: {
150
+ applyLatestCollectionMapping: {
151
+ value: true,
152
+ },
153
+ applyTenantMapping: {
154
+ value: true,
155
+ },
156
+ applyDataProviderMapping: {
157
+ value: ["linolux"],
158
+ },
159
+ },
160
+ }
161
+
162
+ const originalSkus = deepCopy(skus)
163
+
164
+ describe("applyPreferedPropertyMappings", () => {
165
+ it("returns empty array on an empty array", function () {
166
+ expect(applyPreferedPropertyMappings([], {}, [], [], []).length).to.equal(0)
167
+ })
168
+
169
+ it("returns array untouched on an empty configuration", function () {
170
+ expect(applyPreferedPropertyMappings(deepCopy(skus), {}, [], [], [])).to.deep.equal(originalSkus)
171
+ })
172
+
173
+ it("returns array untouched on an empty mapping", function () {
174
+ expect(applyPreferedPropertyMappings(deepCopy(skus), {}, [], [], [])).to.deep.equal(originalSkus)
175
+ })
176
+
177
+ it("returns skus with LatestCollection mapping applied", function () {
178
+ const mappedSkus = applyPreferedPropertyMappings(deepCopy(skus), oneMappingActive, metaDataMapping, dataProviderMapping, tenantMapping)
179
+ expect(mappedSkus[0].colorFamily).to.equal("Wit")
180
+ expect(mappedSkus[1].colorFamily).to.equal("Wit")
181
+ expect(mappedSkus[2].colorFamily).to.equal("Wit")
182
+ expect(mappedSkus[3].colorFamily).to.equal("Blauw")
183
+ expect(mappedSkus[4].colorFamily).to.equal("Blauw")
184
+ expect(mappedSkus[5].colorFamily).to.equal("Blauw")
185
+ expect(mappedSkus[6].colorFamily).to.equal("Blue")
186
+ expect(mappedSkus[7].colorFamily).to.equal("Blue")
187
+ expect(mappedSkus[8].colorFamily).to.equal("Blue")
188
+
189
+ expect(mappedSkus[0].collection).to.equal("22summer")
190
+ expect(mappedSkus[1].collection).to.equal("22summer")
191
+ expect(mappedSkus[2].collection).to.equal("22summer")
192
+ expect(mappedSkus[3].collection).to.equal("22summer")
193
+ expect(mappedSkus[4].collection).to.equal("22summer")
194
+ expect(mappedSkus[5].collection).to.equal("22summer")
195
+ expect(mappedSkus[6].collection).to.equal("22summer")
196
+ expect(mappedSkus[7].collection).to.equal("22summer")
197
+ expect(mappedSkus[8].collection).to.equal("22summer")
198
+ })
199
+
200
+ it("returns skus with LatestCollection and dataProvider mapping applied", function () {
201
+ const mappedSkus = applyPreferedPropertyMappings(deepCopy(skus), twoMappingsActive, metaDataMapping, dataProviderMapping, tenantMapping)
202
+ expect(mappedSkus[0].colorFamily).to.equal("Witter")
203
+ expect(mappedSkus[1].colorFamily).to.equal("Witter")
204
+ expect(mappedSkus[2].colorFamily).to.equal("Witter")
205
+ expect(mappedSkus[3].colorFamily).to.equal("Blauwer")
206
+ expect(mappedSkus[4].colorFamily).to.equal("Blauwer")
207
+ expect(mappedSkus[5].colorFamily).to.equal("Blauwer")
208
+ expect(mappedSkus[6].colorFamily).to.equal("Blue")
209
+ expect(mappedSkus[7].colorFamily).to.equal("Blue")
210
+ expect(mappedSkus[8].colorFamily).to.equal("Blue")
211
+
212
+ expect(mappedSkus[0].collection).to.equal("22zomer")
213
+ expect(mappedSkus[1].collection).to.equal("22zomer")
214
+ expect(mappedSkus[2].collection).to.equal("22zomer")
215
+ expect(mappedSkus[3].collection).to.equal("22zomer")
216
+ expect(mappedSkus[4].collection).to.equal("22zomer")
217
+ expect(mappedSkus[5].collection).to.equal("22zomer")
218
+ expect(mappedSkus[6].collection).to.equal("22summer")
219
+ expect(mappedSkus[7].collection).to.equal("22summer")
220
+ expect(mappedSkus[8].collection).to.equal("22summer")
221
+ })
222
+
223
+ it("returns fully mapped skus on a full mapping", function () {
224
+ const mappedSkus = applyPreferedPropertyMappings(deepCopy(skus), allMappingsActive, metaDataMapping, dataProviderMapping, tenantMapping)
225
+ expect(mappedSkus[0].colorFamily).to.equal("Witter")
226
+ expect(mappedSkus[1].colorFamily).to.equal("Witter")
227
+ expect(mappedSkus[2].colorFamily).to.equal("Witter")
228
+ expect(mappedSkus[3].colorFamily).to.equal("Blauwer")
229
+ expect(mappedSkus[4].colorFamily).to.equal("Blauwer")
230
+ expect(mappedSkus[5].colorFamily).to.equal("Blauwer")
231
+ expect(mappedSkus[6].colorFamily).to.equal("Blue")
232
+ expect(mappedSkus[7].colorFamily).to.equal("Blue")
233
+ expect(mappedSkus[8].colorFamily).to.equal("Blue")
234
+
235
+ expect(mappedSkus[0].collection).to.equal("22zomer")
236
+ expect(mappedSkus[1].collection).to.equal("22zomer")
237
+ expect(mappedSkus[2].collection).to.equal("22zomer")
238
+ expect(mappedSkus[3].collection).to.equal("22zomer")
239
+ expect(mappedSkus[4].collection).to.equal("22zomer")
240
+ expect(mappedSkus[5].collection).to.equal("22zomer")
241
+ expect(mappedSkus[6].collection).to.equal("22zomer")
242
+ expect(mappedSkus[7].collection).to.equal("22zomer")
243
+ expect(mappedSkus[8].collection).to.equal("22zomer")
244
+ })
245
+ })
@@ -124,9 +124,6 @@ const fullMapping = [
124
124
  const originalSkus = deepCopy(skus)
125
125
 
126
126
  describe("applyPropertyMapping", () => {
127
- before(() => {
128
- expect(applyPropertyMapping, "applyPropertyMapping").to.be.a("function")
129
- })
130
127
  it("returns empty array on an empty array", function () {
131
128
  expect(applyPropertyMapping([], []).length).to.equal(0)
132
129
  })