@softwear/latestcollectioncore 1.0.34 → 1.0.35

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,71 +1,74 @@
1
- const { deepCopy, buildPropertyMappingFn, getPreferedPropertyMappings } = require("../dist/index")
2
- const { expect } = require("chai")
1
+ const {
2
+ deepCopy,
3
+ buildPropertyMappingFn,
4
+ getPreferedPropertyMappings,
5
+ } = require("../dist/index");
6
+ const { expect } = require("chai");
3
7
 
4
- const applyPreferedPropertyMappings = function (skus, activeConfig, metaBrandSetting, dataProviderBrandSetting, tenantBrandSetting) {
5
- const allMappings = getPreferedPropertyMappings(activeConfig, metaBrandSetting, dataProviderBrandSetting, tenantBrandSetting)
6
- const mapper = buildPropertyMappingFn(allMappings)
7
- return skus.map(mapper)
8
- }
8
+ const applyPreferedPropertyMappings = function (
9
+ skus,
10
+ activeConfig,
11
+ metaBrandSetting,
12
+ dataProviderBrandSetting,
13
+ tenantBrandSetting
14
+ ) {
15
+ const allMappings = getPreferedPropertyMappings(
16
+ activeConfig,
17
+ metaBrandSetting,
18
+ dataProviderBrandSetting,
19
+ tenantBrandSetting
20
+ );
21
+ const mapper = buildPropertyMappingFn(allMappings);
22
+ return skus.map(mapper);
23
+ };
9
24
 
10
25
  const skus = [
11
26
  {
12
27
  id: "1234567890128",
13
28
  brand: "levis",
14
- collection: "22summer",
29
+ collection: "User defined value wins",
15
30
  collectionSupplier: "SUMMER 2022",
16
31
  colorCodeSupplier: "100",
17
- colorFamily: "White",
18
32
  size: "S",
19
33
  },
20
34
  {
21
35
  id: "1234567890129",
22
36
  brand: "levis",
23
- collection: "22summer",
24
37
  collectionSupplier: "SUMMER 2022",
25
38
  colorCodeSupplier: "100",
26
- colorFamily: "White",
27
39
  size: "M",
28
40
  },
29
41
  {
30
42
  id: "1234567890130",
31
43
  brand: "levis",
32
- collection: "22summer",
33
44
  collectionSupplier: "SUMMER 2022",
34
45
  colorCodeSupplier: "100",
35
- colorFamily: "White",
36
46
  size: "L",
37
47
  },
38
48
  {
39
49
  id: "1234567890131",
40
50
  brand: "levis",
41
- collection: "22summer",
42
51
  collectionSupplier: "SUMMER 2022",
43
52
  colorCodeSupplier: "200",
44
- colorFamily: "Blue",
45
53
  size: "S",
46
54
  },
47
55
  {
48
56
  id: "1234567890132",
49
57
  brand: "levis",
50
- collection: "22summer",
51
58
  collectionSupplier: "SUMMER 2022",
52
59
  colorCodeSupplier: "200",
53
- colorFamily: "Blue",
54
60
  size: "M",
55
61
  },
56
62
  {
57
63
  id: "1234567890133",
58
64
  brand: "levis",
59
- collection: "22summer",
60
65
  collectionSupplier: "SUMMER 2022",
61
66
  colorCodeSupplier: "200",
62
- colorFamily: "Blue",
63
67
  size: "L",
64
68
  },
65
69
  {
66
70
  id: "1234567890134",
67
71
  brand: "gstar",
68
- collection: "22summer",
69
72
  collectionSupplier: "SUMMER 2022",
70
73
  colorCodeSupplier: "200",
71
74
  colorFamily: "Blue",
@@ -74,7 +77,6 @@ const skus = [
74
77
  {
75
78
  id: "1234567890135",
76
79
  brand: "gstar",
77
- collection: "22summer",
78
80
  collectionSupplier: "SUMMER 2022",
79
81
  colorCodeSupplier: "200",
80
82
  colorFamily: "Blue",
@@ -83,46 +85,61 @@ const skus = [
83
85
  {
84
86
  id: "1234567890136",
85
87
  brand: "gstar",
86
- collection: "22summer",
87
88
  collectionSupplier: "SUMMER 2022",
88
89
  colorCodeSupplier: "200",
89
90
  colorFamily: "Blue",
90
91
  size: "L",
91
92
  },
92
- ]
93
+ ];
93
94
 
94
95
  const metaDataMapping = [
95
96
  {
96
97
  id: "levis",
97
98
  propertyMapping: [
98
- { category: "ColorCode", from: "200", to: "Blauw" },
99
- { category: "ColorCode", from: "100", to: "Wit" },
99
+ { category: "ColorCode", from: "200", to: "Blauw-metaDataMapping" },
100
+ { category: "ColorCode", from: "100", to: "Wit-metaDataMapping" },
100
101
  ],
101
102
  },
102
- ]
103
+ ];
103
104
 
104
105
  const dataProviderMapping = [
105
106
  {
106
107
  id: "levis:linolux",
107
108
  dataProvider: "linolux",
108
109
  propertyMapping: [
109
- { category: "ColorCode", from: "200", to: "Blauwer" },
110
- { category: "ColorCode", from: "100", to: "Witter" },
111
- { category: "Collection", from: "SUMMER 2022", to: "22zomer" },
110
+ {
111
+ category: "ColorCode",
112
+ from: "200",
113
+ to: "Blauwer-dataProviderMapping",
114
+ },
115
+ {
116
+ category: "ColorCode",
117
+ from: "100",
118
+ to: "Witter-dataProviderMapping",
119
+ },
120
+ {
121
+ category: "Collection",
122
+ from: "SUMMER 2022",
123
+ to: "22zomer-dataProviderMapping",
124
+ },
112
125
  ],
113
126
  },
114
- ]
127
+ ];
115
128
 
116
129
  const tenantMapping = [
117
130
  {
118
131
  id: "levis",
119
- propertyMapping: [{ category: "Collection", from: "SUMMER 2022", to: "22zomer" }],
132
+ propertyMapping: [
133
+ { category: "Collection", from: "SUMMER 2022", to: "22zomer" },
134
+ ],
120
135
  },
121
136
  {
122
137
  id: "gstar",
123
- propertyMapping: [{ category: "Collection", from: "SUMMER 2022", to: "22zomer" }],
138
+ propertyMapping: [
139
+ { category: "Collection", from: "SUMMER 2022", to: "22zomer" },
140
+ ],
124
141
  },
125
- ]
142
+ ];
126
143
 
127
144
  const oneMappingActive = {
128
145
  products: {
@@ -136,7 +153,7 @@ const oneMappingActive = {
136
153
  value: [],
137
154
  },
138
155
  },
139
- }
156
+ };
140
157
 
141
158
  const twoMappingsActive = {
142
159
  products: {
@@ -150,7 +167,7 @@ const twoMappingsActive = {
150
167
  value: ["linolux"],
151
168
  },
152
169
  },
153
- }
170
+ };
154
171
  const allMappingsActive = {
155
172
  products: {
156
173
  applyLatestCollectionMapping: {
@@ -163,89 +180,121 @@ const allMappingsActive = {
163
180
  value: ["linolux"],
164
181
  },
165
182
  },
166
- }
167
-
168
- const originalSkus = deepCopy(skus)
183
+ };
169
184
 
170
185
  describe("applyPreferedPropertyMappings", () => {
171
186
  it("returns empty array on an empty array", function () {
172
- expect(applyPreferedPropertyMappings([], {}, [], [], []).length).to.equal(0)
173
- })
174
-
175
- it("returns array untouched on an empty configuration", function () {
176
- expect(applyPreferedPropertyMappings(deepCopy(skus), {}, [], [], [])).to.deep.equal(originalSkus)
177
- })
187
+ expect(applyPreferedPropertyMappings([], {}, [], [], []).length).to.equal(
188
+ 0
189
+ );
190
+ });
178
191
 
179
- it("returns array untouched on an empty mapping", function () {
180
- expect(applyPreferedPropertyMappings(deepCopy(skus), {}, [], [], [])).to.deep.equal(originalSkus)
181
- })
192
+ it("returns array with missing properties copied from supplierFields on a missing configuration", function () {
193
+ const mappedSkus = applyPreferedPropertyMappings(
194
+ deepCopy(skus),
195
+ {},
196
+ [],
197
+ [],
198
+ []
199
+ );
200
+ expect(mappedSkus[0]).to.deep.equal({
201
+ id: "1234567890128",
202
+ brand: "levis",
203
+ collectionSupplier: "SUMMER 2022",
204
+ colorCodeSupplier: "100",
205
+ size: "S",
206
+ colorFamily: "100",
207
+ articleGroup: "",
208
+ collection: "User defined value wins",
209
+ _customsize: "",
210
+ _gender: "",
211
+ });
212
+ });
182
213
 
183
214
  it("returns skus with LatestCollection mapping applied", function () {
184
- const mappedSkus = applyPreferedPropertyMappings(deepCopy(skus), oneMappingActive, metaDataMapping, dataProviderMapping, tenantMapping)
185
- expect(mappedSkus[0].colorFamily).to.equal("Wit")
186
- expect(mappedSkus[1].colorFamily).to.equal("Wit")
187
- expect(mappedSkus[2].colorFamily).to.equal("Wit")
188
- expect(mappedSkus[3].colorFamily).to.equal("Blauw")
189
- expect(mappedSkus[4].colorFamily).to.equal("Blauw")
190
- expect(mappedSkus[5].colorFamily).to.equal("Blauw")
191
- expect(mappedSkus[6].colorFamily).to.equal("Blue")
192
- expect(mappedSkus[7].colorFamily).to.equal("Blue")
193
- expect(mappedSkus[8].colorFamily).to.equal("Blue")
215
+ const mappedSkus = applyPreferedPropertyMappings(
216
+ deepCopy(skus),
217
+ oneMappingActive,
218
+ metaDataMapping,
219
+ dataProviderMapping,
220
+ tenantMapping
221
+ );
222
+ expect(mappedSkus[0].colorFamily).to.equal("Wit-metaDataMapping");
223
+ expect(mappedSkus[1].colorFamily).to.equal("Wit-metaDataMapping");
224
+ expect(mappedSkus[2].colorFamily).to.equal("Wit-metaDataMapping");
225
+ expect(mappedSkus[3].colorFamily).to.equal("Blauw-metaDataMapping");
226
+ expect(mappedSkus[4].colorFamily).to.equal("Blauw-metaDataMapping");
227
+ expect(mappedSkus[5].colorFamily).to.equal("Blauw-metaDataMapping");
228
+ expect(mappedSkus[6].colorFamily).to.equal("Blue");
229
+ expect(mappedSkus[7].colorFamily).to.equal("Blue");
230
+ expect(mappedSkus[8].colorFamily).to.equal("Blue");
194
231
 
195
- expect(mappedSkus[0].collection).to.equal("22summer")
196
- expect(mappedSkus[1].collection).to.equal("22summer")
197
- expect(mappedSkus[2].collection).to.equal("22summer")
198
- expect(mappedSkus[3].collection).to.equal("22summer")
199
- expect(mappedSkus[4].collection).to.equal("22summer")
200
- expect(mappedSkus[5].collection).to.equal("22summer")
201
- expect(mappedSkus[6].collection).to.equal("22summer")
202
- expect(mappedSkus[7].collection).to.equal("22summer")
203
- expect(mappedSkus[8].collection).to.equal("22summer")
204
- })
232
+ expect(mappedSkus[0].collection).to.equal("User defined value wins");
233
+ expect(mappedSkus[1].collection).to.equal("SUMMER 2022");
234
+ expect(mappedSkus[2].collection).to.equal("SUMMER 2022");
235
+ expect(mappedSkus[3].collection).to.equal("SUMMER 2022");
236
+ expect(mappedSkus[4].collection).to.equal("SUMMER 2022");
237
+ expect(mappedSkus[5].collection).to.equal("SUMMER 2022");
238
+ expect(mappedSkus[6].collection).to.equal("SUMMER 2022");
239
+ expect(mappedSkus[7].collection).to.equal("SUMMER 2022");
240
+ expect(mappedSkus[8].collection).to.equal("SUMMER 2022");
241
+ });
205
242
 
206
243
  it("returns skus with LatestCollection and dataProvider mapping applied", function () {
207
- const mappedSkus = applyPreferedPropertyMappings(deepCopy(skus), twoMappingsActive, metaDataMapping, dataProviderMapping, tenantMapping)
208
- expect(mappedSkus[0].colorFamily).to.equal("Witter")
209
- expect(mappedSkus[1].colorFamily).to.equal("Witter")
210
- expect(mappedSkus[2].colorFamily).to.equal("Witter")
211
- expect(mappedSkus[3].colorFamily).to.equal("Blauwer")
212
- expect(mappedSkus[4].colorFamily).to.equal("Blauwer")
213
- expect(mappedSkus[5].colorFamily).to.equal("Blauwer")
214
- expect(mappedSkus[6].colorFamily).to.equal("Blue")
215
- expect(mappedSkus[7].colorFamily).to.equal("Blue")
216
- expect(mappedSkus[8].colorFamily).to.equal("Blue")
244
+ const mappedSkus = applyPreferedPropertyMappings(
245
+ deepCopy(skus),
246
+ twoMappingsActive,
247
+ metaDataMapping,
248
+ dataProviderMapping,
249
+ tenantMapping
250
+ );
251
+ expect(mappedSkus[0].colorFamily).to.equal("Witter-dataProviderMapping");
252
+ expect(mappedSkus[1].colorFamily).to.equal("Witter-dataProviderMapping");
253
+ expect(mappedSkus[2].colorFamily).to.equal("Witter-dataProviderMapping");
254
+ expect(mappedSkus[3].colorFamily).to.equal("Blauwer-dataProviderMapping");
255
+ expect(mappedSkus[4].colorFamily).to.equal("Blauwer-dataProviderMapping");
256
+ expect(mappedSkus[5].colorFamily).to.equal("Blauwer-dataProviderMapping");
257
+ expect(mappedSkus[6].colorFamily).to.equal("Blue");
258
+ expect(mappedSkus[7].colorFamily).to.equal("Blue");
259
+ expect(mappedSkus[8].colorFamily).to.equal("Blue");
217
260
 
218
- expect(mappedSkus[0].collection).to.equal("22zomer")
219
- expect(mappedSkus[1].collection).to.equal("22zomer")
220
- expect(mappedSkus[2].collection).to.equal("22zomer")
221
- expect(mappedSkus[3].collection).to.equal("22zomer")
222
- expect(mappedSkus[4].collection).to.equal("22zomer")
223
- expect(mappedSkus[5].collection).to.equal("22zomer")
224
- expect(mappedSkus[6].collection).to.equal("22summer")
225
- expect(mappedSkus[7].collection).to.equal("22summer")
226
- expect(mappedSkus[8].collection).to.equal("22summer")
227
- })
261
+ expect(mappedSkus[0].collection).to.equal("User defined value wins");
262
+ expect(mappedSkus[1].collection).to.equal("22zomer-dataProviderMapping");
263
+ expect(mappedSkus[2].collection).to.equal("22zomer-dataProviderMapping");
264
+ expect(mappedSkus[3].collection).to.equal("22zomer-dataProviderMapping");
265
+ expect(mappedSkus[4].collection).to.equal("22zomer-dataProviderMapping");
266
+ expect(mappedSkus[5].collection).to.equal("22zomer-dataProviderMapping");
267
+ expect(mappedSkus[6].collection).to.equal("SUMMER 2022");
268
+ expect(mappedSkus[7].collection).to.equal("SUMMER 2022");
269
+ expect(mappedSkus[8].collection).to.equal("SUMMER 2022");
270
+ });
228
271
 
229
272
  it("returns fully mapped skus on a full mapping", function () {
230
- const mappedSkus = applyPreferedPropertyMappings(deepCopy(skus), allMappingsActive, metaDataMapping, dataProviderMapping, tenantMapping)
231
- expect(mappedSkus[0].colorFamily).to.equal("Witter")
232
- expect(mappedSkus[1].colorFamily).to.equal("Witter")
233
- expect(mappedSkus[2].colorFamily).to.equal("Witter")
234
- expect(mappedSkus[3].colorFamily).to.equal("Blauwer")
235
- expect(mappedSkus[4].colorFamily).to.equal("Blauwer")
236
- expect(mappedSkus[5].colorFamily).to.equal("Blauwer")
237
- expect(mappedSkus[6].colorFamily).to.equal("Blue")
238
- expect(mappedSkus[7].colorFamily).to.equal("Blue")
239
- expect(mappedSkus[8].colorFamily).to.equal("Blue")
273
+ const mappedSkus = applyPreferedPropertyMappings(
274
+ deepCopy(skus),
275
+ allMappingsActive,
276
+ metaDataMapping,
277
+ dataProviderMapping,
278
+ tenantMapping
279
+ );
280
+ expect(mappedSkus[0].colorFamily).to.equal("Witter-dataProviderMapping");
281
+ expect(mappedSkus[1].colorFamily).to.equal("Witter-dataProviderMapping");
282
+ expect(mappedSkus[2].colorFamily).to.equal("Witter-dataProviderMapping");
283
+ expect(mappedSkus[3].colorFamily).to.equal("Blauwer-dataProviderMapping");
284
+ expect(mappedSkus[4].colorFamily).to.equal("Blauwer-dataProviderMapping");
285
+ expect(mappedSkus[5].colorFamily).to.equal("Blauwer-dataProviderMapping");
286
+ expect(mappedSkus[6].colorFamily).to.equal("Blue");
287
+ expect(mappedSkus[7].colorFamily).to.equal("Blue");
288
+ expect(mappedSkus[8].colorFamily).to.equal("Blue");
240
289
 
241
- expect(mappedSkus[0].collection).to.equal("22zomer")
242
- expect(mappedSkus[1].collection).to.equal("22zomer")
243
- expect(mappedSkus[2].collection).to.equal("22zomer")
244
- expect(mappedSkus[3].collection).to.equal("22zomer")
245
- expect(mappedSkus[4].collection).to.equal("22zomer")
246
- expect(mappedSkus[5].collection).to.equal("22zomer")
247
- expect(mappedSkus[6].collection).to.equal("22zomer")
248
- expect(mappedSkus[7].collection).to.equal("22zomer")
249
- expect(mappedSkus[8].collection).to.equal("22zomer")
250
- })
251
- })
290
+ expect(mappedSkus[0].collection).to.equal("User defined value wins");
291
+ expect(mappedSkus[1].collection).to.equal("22zomer");
292
+ expect(mappedSkus[2].collection).to.equal("22zomer");
293
+ expect(mappedSkus[3].collection).to.equal("22zomer");
294
+ expect(mappedSkus[4].collection).to.equal("22zomer");
295
+ expect(mappedSkus[5].collection).to.equal("22zomer");
296
+ expect(mappedSkus[6].collection).to.equal("22zomer");
297
+ expect(mappedSkus[7].collection).to.equal("22zomer");
298
+ expect(mappedSkus[8].collection).to.equal("22zomer");
299
+ });
300
+ });