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