@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.
- package/dist/buildPropertyMappingFn.d.ts +2 -2
- package/dist/buildPropertyMappingFn.js +40 -68
- package/dist/types.d.ts +5 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
- package/src/buildPropertyMappingFn.ts +46 -62
- package/src/types.ts +154 -149
- package/test/applyPreferedPropertyMappings.spec.js +157 -108
- package/test/applyPropertyMapping.spec.js +182 -109
|
@@ -1,71 +1,74 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
1
|
+
const {
|
|
2
|
+
deepCopy,
|
|
3
|
+
buildPropertyMappingFn,
|
|
4
|
+
getPreferedPropertyMappings,
|
|
5
|
+
} = require("../dist/index");
|
|
6
|
+
const { expect } = require("chai");
|
|
3
7
|
|
|
4
|
-
const applyPreferedPropertyMappings = function (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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: "
|
|
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
|
-
{
|
|
110
|
-
|
|
111
|
-
|
|
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: [
|
|
132
|
+
propertyMapping: [
|
|
133
|
+
{ category: "Collection", from: "SUMMER 2022", to: "22zomer" },
|
|
134
|
+
],
|
|
120
135
|
},
|
|
121
136
|
{
|
|
122
137
|
id: "gstar",
|
|
123
|
-
propertyMapping: [
|
|
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(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
|
180
|
-
|
|
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(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
expect(mappedSkus[
|
|
192
|
-
expect(mappedSkus[
|
|
193
|
-
expect(mappedSkus[
|
|
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("
|
|
196
|
-
expect(mappedSkus[1].collection).to.equal("
|
|
197
|
-
expect(mappedSkus[2].collection).to.equal("
|
|
198
|
-
expect(mappedSkus[3].collection).to.equal("
|
|
199
|
-
expect(mappedSkus[4].collection).to.equal("
|
|
200
|
-
expect(mappedSkus[5].collection).to.equal("
|
|
201
|
-
expect(mappedSkus[6].collection).to.equal("
|
|
202
|
-
expect(mappedSkus[7].collection).to.equal("
|
|
203
|
-
expect(mappedSkus[8].collection).to.equal("
|
|
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(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
expect(mappedSkus[
|
|
215
|
-
expect(mappedSkus[
|
|
216
|
-
expect(mappedSkus[
|
|
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("
|
|
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("
|
|
225
|
-
expect(mappedSkus[7].collection).to.equal("
|
|
226
|
-
expect(mappedSkus[8].collection).to.equal("
|
|
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(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
expect(mappedSkus[
|
|
238
|
-
expect(mappedSkus[
|
|
239
|
-
expect(mappedSkus[
|
|
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("
|
|
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
|
+
});
|