@softwear/latestcollectioncore 1.0.7 → 1.0.9
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/applyPropertyMapping.d.ts +2 -0
- package/dist/applyPropertyMapping.js +97 -0
- package/dist/deepCopy.d.ts +1 -0
- package/dist/deepCopy.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/package.json +1 -1
- package/src/applyPropertyMapping.ts +80 -0
- package/src/deepCopy.ts +4 -0
- package/src/index.ts +2 -0
- package/test/applyPropertyMapping.spec.js +206 -0
- package/test/deepCopy.spec.js +17 -0
- package/test/ean13.spec.js +2 -2
- package/test/hashBrand.spec.js +5 -5
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
function default_1(skus, brands) {
|
|
5
|
+
// Helper function to convert all mapping rules for given category to an indexed object
|
|
6
|
+
const indexedMapping = function (propertyMapping, category) {
|
|
7
|
+
const filteredMappings = propertyMapping.filter((mapping) => mapping.category == category && mapping.from);
|
|
8
|
+
if (filteredMappings.length == 0)
|
|
9
|
+
return undefined;
|
|
10
|
+
return filteredMappings.reduce((acc, item) => {
|
|
11
|
+
acc[item.from] = item.to;
|
|
12
|
+
return acc;
|
|
13
|
+
}, {});
|
|
14
|
+
};
|
|
15
|
+
// Helper function to convert all mapping rules to an indexed object
|
|
16
|
+
const indexFn = function (propertyMapping) {
|
|
17
|
+
if (!propertyMapping)
|
|
18
|
+
return {};
|
|
19
|
+
const maps = {};
|
|
20
|
+
index_1.MAPPING_CATEGORIES.forEach((category) => {
|
|
21
|
+
const map = indexedMapping(propertyMapping, category);
|
|
22
|
+
if (map !== undefined)
|
|
23
|
+
maps[category] = map;
|
|
24
|
+
});
|
|
25
|
+
return maps;
|
|
26
|
+
};
|
|
27
|
+
const indexedPropertyMapping = brands.reduce((acc, item) => {
|
|
28
|
+
acc[item.id] = indexFn(item.propertyMapping);
|
|
29
|
+
return acc;
|
|
30
|
+
}, {});
|
|
31
|
+
return skus.map((sku) => {
|
|
32
|
+
const brand = (0, index_1.hashBrand)(sku.brand);
|
|
33
|
+
const mapping = indexedPropertyMapping[brand];
|
|
34
|
+
if (!mapping)
|
|
35
|
+
return sku;
|
|
36
|
+
if (mapping.ColorCode) {
|
|
37
|
+
const from = sku.colorCodeSupplier;
|
|
38
|
+
if (!from)
|
|
39
|
+
return;
|
|
40
|
+
const to = indexedPropertyMapping[brand].ColorCode[from];
|
|
41
|
+
if (to && to != sku.colorFamily)
|
|
42
|
+
sku.colorFamily = to;
|
|
43
|
+
}
|
|
44
|
+
if (mapping.ColorDescription) {
|
|
45
|
+
const from = sku.colorSupplier;
|
|
46
|
+
if (!from)
|
|
47
|
+
return;
|
|
48
|
+
const to = indexedPropertyMapping[brand].ColorDescription[from];
|
|
49
|
+
if (to && to != sku.colorFamily)
|
|
50
|
+
sku.colorFamily = to;
|
|
51
|
+
}
|
|
52
|
+
if (mapping.ProductGroup) {
|
|
53
|
+
const from = sku.articleGroupSupplier;
|
|
54
|
+
if (!from)
|
|
55
|
+
return;
|
|
56
|
+
const to = indexedPropertyMapping[brand].ProductGroup[from];
|
|
57
|
+
if (to && to != sku.articleGroup)
|
|
58
|
+
sku.articleGroup = to;
|
|
59
|
+
}
|
|
60
|
+
if (mapping.Collection) {
|
|
61
|
+
const from = sku.collectionSupplier;
|
|
62
|
+
if (!from)
|
|
63
|
+
return;
|
|
64
|
+
const to = indexedPropertyMapping[brand].Collection[from];
|
|
65
|
+
if (to && to != sku.collection)
|
|
66
|
+
sku.collection = to;
|
|
67
|
+
}
|
|
68
|
+
if (mapping.Size) {
|
|
69
|
+
const from = sku.sizeSupplier;
|
|
70
|
+
if (!from)
|
|
71
|
+
return;
|
|
72
|
+
const to = indexedPropertyMapping[brand].Size[from];
|
|
73
|
+
if (to && to != sku.size) {
|
|
74
|
+
sku.size = to;
|
|
75
|
+
sku.mainSize = to;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (mapping.SubSize) {
|
|
79
|
+
const from = sku.sizeSupplier;
|
|
80
|
+
if (!from)
|
|
81
|
+
return;
|
|
82
|
+
const to = indexedPropertyMapping[brand].SubSize[from];
|
|
83
|
+
if (to && to != sku.subSize)
|
|
84
|
+
sku.subSize = to;
|
|
85
|
+
}
|
|
86
|
+
if (mapping.CustomSize) {
|
|
87
|
+
const from = sku.sizeSupplier;
|
|
88
|
+
if (!from)
|
|
89
|
+
return;
|
|
90
|
+
const to = indexedPropertyMapping[brand].CustomSize[from];
|
|
91
|
+
if (to && to != sku["_customSize"])
|
|
92
|
+
sku["_customSize"] = to;
|
|
93
|
+
}
|
|
94
|
+
return sku;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exports.default = default_1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (object: any): any;
|
package/dist/deepCopy.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { default as applyPropertyMapping } from "./applyPropertyMapping";
|
|
1
2
|
export { default as ean13 } from "./ean13";
|
|
3
|
+
export { default as deepCopy } from "./deepCopy";
|
|
2
4
|
export { default as hashBrand } from "./hashBrand";
|
|
3
5
|
export * from "./types";
|
|
4
6
|
export * from "./consts";
|
package/dist/index.js
CHANGED
|
@@ -17,9 +17,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.hashBrand = exports.ean13 = void 0;
|
|
20
|
+
exports.hashBrand = exports.deepCopy = exports.ean13 = exports.applyPropertyMapping = void 0;
|
|
21
|
+
var applyPropertyMapping_1 = require("./applyPropertyMapping");
|
|
22
|
+
Object.defineProperty(exports, "applyPropertyMapping", { enumerable: true, get: function () { return __importDefault(applyPropertyMapping_1).default; } });
|
|
21
23
|
var ean13_1 = require("./ean13");
|
|
22
24
|
Object.defineProperty(exports, "ean13", { enumerable: true, get: function () { return __importDefault(ean13_1).default; } });
|
|
25
|
+
var deepCopy_1 = require("./deepCopy");
|
|
26
|
+
Object.defineProperty(exports, "deepCopy", { enumerable: true, get: function () { return __importDefault(deepCopy_1).default; } });
|
|
23
27
|
var hashBrand_1 = require("./hashBrand");
|
|
24
28
|
Object.defineProperty(exports, "hashBrand", { enumerable: true, get: function () { return __importDefault(hashBrand_1).default; } });
|
|
25
29
|
__exportStar(require("./types"), exports);
|
package/package.json
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { hashBrand, SkuI, MAPPING_CATEGORIES } from "./index"
|
|
2
|
+
|
|
3
|
+
export default function (skus: Array<SkuI>, brands: Array<any>): any {
|
|
4
|
+
// Helper function to convert all mapping rules for given category to an indexed object
|
|
5
|
+
const indexedMapping = function (propertyMapping, category) {
|
|
6
|
+
const filteredMappings = propertyMapping.filter((mapping) => mapping.category == category && mapping.from)
|
|
7
|
+
|
|
8
|
+
if (filteredMappings.length == 0) return undefined
|
|
9
|
+
return filteredMappings.reduce((acc, item) => {
|
|
10
|
+
acc[item.from] = item.to
|
|
11
|
+
return acc
|
|
12
|
+
}, {})
|
|
13
|
+
}
|
|
14
|
+
// Helper function to convert all mapping rules to an indexed object
|
|
15
|
+
const indexFn = function (propertyMapping) {
|
|
16
|
+
if (!propertyMapping) return {}
|
|
17
|
+
const maps = {}
|
|
18
|
+
MAPPING_CATEGORIES.forEach((category) => {
|
|
19
|
+
const map = indexedMapping(propertyMapping, category)
|
|
20
|
+
if (map !== undefined) maps[category] = map
|
|
21
|
+
})
|
|
22
|
+
return maps
|
|
23
|
+
}
|
|
24
|
+
const indexedPropertyMapping = brands.reduce((acc, item) => {
|
|
25
|
+
acc[item.id] = indexFn(item.propertyMapping)
|
|
26
|
+
return acc
|
|
27
|
+
}, {})
|
|
28
|
+
return skus.map((sku: SkuI) => {
|
|
29
|
+
const brand = hashBrand(sku.brand)
|
|
30
|
+
const mapping = indexedPropertyMapping[brand]
|
|
31
|
+
if (!mapping) return sku
|
|
32
|
+
|
|
33
|
+
if (mapping.ColorCode) {
|
|
34
|
+
const from = sku.colorCodeSupplier
|
|
35
|
+
if (!from) return
|
|
36
|
+
const to = indexedPropertyMapping[brand].ColorCode[from]
|
|
37
|
+
if (to && to != sku.colorFamily) sku.colorFamily = to
|
|
38
|
+
}
|
|
39
|
+
if (mapping.ColorDescription) {
|
|
40
|
+
const from = sku.colorSupplier
|
|
41
|
+
if (!from) return
|
|
42
|
+
const to = indexedPropertyMapping[brand].ColorDescription[from]
|
|
43
|
+
if (to && to != sku.colorFamily) sku.colorFamily = to
|
|
44
|
+
}
|
|
45
|
+
if (mapping.ProductGroup) {
|
|
46
|
+
const from = sku.articleGroupSupplier
|
|
47
|
+
if (!from) return
|
|
48
|
+
const to = indexedPropertyMapping[brand].ProductGroup[from]
|
|
49
|
+
if (to && to != sku.articleGroup) sku.articleGroup = to
|
|
50
|
+
}
|
|
51
|
+
if (mapping.Collection) {
|
|
52
|
+
const from = sku.collectionSupplier
|
|
53
|
+
if (!from) return
|
|
54
|
+
const to = indexedPropertyMapping[brand].Collection[from]
|
|
55
|
+
if (to && to != sku.collection) sku.collection = to
|
|
56
|
+
}
|
|
57
|
+
if (mapping.Size) {
|
|
58
|
+
const from = sku.sizeSupplier
|
|
59
|
+
if (!from) return
|
|
60
|
+
const to = indexedPropertyMapping[brand].Size[from]
|
|
61
|
+
if (to && to != sku.size) {
|
|
62
|
+
sku.size = to
|
|
63
|
+
sku.mainSize = to
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (mapping.SubSize) {
|
|
67
|
+
const from = sku.sizeSupplier
|
|
68
|
+
if (!from) return
|
|
69
|
+
const to = indexedPropertyMapping[brand].SubSize[from]
|
|
70
|
+
if (to && to != sku.subSize) sku.subSize = to
|
|
71
|
+
}
|
|
72
|
+
if (mapping.CustomSize) {
|
|
73
|
+
const from = sku.sizeSupplier
|
|
74
|
+
if (!from) return
|
|
75
|
+
const to = indexedPropertyMapping[brand].CustomSize[from]
|
|
76
|
+
if (to && to != sku["_customSize"]) sku["_customSize"] = to
|
|
77
|
+
}
|
|
78
|
+
return sku
|
|
79
|
+
})
|
|
80
|
+
}
|
package/src/deepCopy.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { default as applyPropertyMapping } from "./applyPropertyMapping"
|
|
1
2
|
export { default as ean13 } from "./ean13"
|
|
3
|
+
export { default as deepCopy } from "./deepCopy"
|
|
2
4
|
export { default as hashBrand } from "./hashBrand"
|
|
3
5
|
export * from "./types"
|
|
4
6
|
export * from "./consts"
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
const { deepCopy, applyPropertyMapping } = 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 colorMapping = [
|
|
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 partialMapping = [
|
|
99
|
+
{
|
|
100
|
+
id: "levis",
|
|
101
|
+
propertyMapping: [
|
|
102
|
+
{ category: "ColorCode", from: "200", to: "Blauw" },
|
|
103
|
+
{ category: "ColorCode", from: "100", to: "Wit" },
|
|
104
|
+
{ category: "Collection", from: "SUMMER 2022", to: "22zomer" },
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
const fullMapping = [
|
|
110
|
+
{
|
|
111
|
+
id: "levis",
|
|
112
|
+
propertyMapping: [
|
|
113
|
+
{ category: "ColorCode", from: "200", to: "Blauw" },
|
|
114
|
+
{ category: "ColorCode", from: "100", to: "Wit" },
|
|
115
|
+
{ category: "Collection", from: "SUMMER 2022", to: "22zomer" },
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "gstar",
|
|
120
|
+
propertyMapping: [{ category: "Collection", from: "SUMMER 2022", to: "22zomer" }],
|
|
121
|
+
},
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
const originalSkus = deepCopy(skus)
|
|
125
|
+
|
|
126
|
+
describe("applyPropertyMapping", () => {
|
|
127
|
+
before(() => {
|
|
128
|
+
expect(applyPropertyMapping, "applyPropertyMapping").to.be.a("function")
|
|
129
|
+
})
|
|
130
|
+
it("returns empty array on an empty array", function () {
|
|
131
|
+
expect(applyPropertyMapping([], []).length).to.equal(0)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it("returns array untouched on an empty mapping", function () {
|
|
135
|
+
expect(applyPropertyMapping(skus, [])).to.deep.equal(originalSkus)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it("returns mapped colors on a color mapping", function () {
|
|
139
|
+
const mappedSkus = applyPropertyMapping(skus, colorMapping)
|
|
140
|
+
expect(mappedSkus[0].colorFamily).to.equal("Wit")
|
|
141
|
+
expect(mappedSkus[1].colorFamily).to.equal("Wit")
|
|
142
|
+
expect(mappedSkus[2].colorFamily).to.equal("Wit")
|
|
143
|
+
expect(mappedSkus[3].colorFamily).to.equal("Blauw")
|
|
144
|
+
expect(mappedSkus[4].colorFamily).to.equal("Blauw")
|
|
145
|
+
expect(mappedSkus[5].colorFamily).to.equal("Blauw")
|
|
146
|
+
expect(mappedSkus[6].colorFamily).to.equal("Blue")
|
|
147
|
+
expect(mappedSkus[7].colorFamily).to.equal("Blue")
|
|
148
|
+
expect(mappedSkus[8].colorFamily).to.equal("Blue")
|
|
149
|
+
|
|
150
|
+
expect(mappedSkus[0].collection).to.equal("22summer")
|
|
151
|
+
expect(mappedSkus[1].collection).to.equal("22summer")
|
|
152
|
+
expect(mappedSkus[2].collection).to.equal("22summer")
|
|
153
|
+
expect(mappedSkus[3].collection).to.equal("22summer")
|
|
154
|
+
expect(mappedSkus[4].collection).to.equal("22summer")
|
|
155
|
+
expect(mappedSkus[5].collection).to.equal("22summer")
|
|
156
|
+
expect(mappedSkus[6].collection).to.equal("22summer")
|
|
157
|
+
expect(mappedSkus[7].collection).to.equal("22summer")
|
|
158
|
+
expect(mappedSkus[8].collection).to.equal("22summer")
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it("returns partially mapped skus on a partial mapping", function () {
|
|
162
|
+
const mappedSkus = applyPropertyMapping(skus, partialMapping)
|
|
163
|
+
expect(mappedSkus[0].colorFamily).to.equal("Wit")
|
|
164
|
+
expect(mappedSkus[1].colorFamily).to.equal("Wit")
|
|
165
|
+
expect(mappedSkus[2].colorFamily).to.equal("Wit")
|
|
166
|
+
expect(mappedSkus[3].colorFamily).to.equal("Blauw")
|
|
167
|
+
expect(mappedSkus[4].colorFamily).to.equal("Blauw")
|
|
168
|
+
expect(mappedSkus[5].colorFamily).to.equal("Blauw")
|
|
169
|
+
expect(mappedSkus[6].colorFamily).to.equal("Blue")
|
|
170
|
+
expect(mappedSkus[7].colorFamily).to.equal("Blue")
|
|
171
|
+
expect(mappedSkus[8].colorFamily).to.equal("Blue")
|
|
172
|
+
|
|
173
|
+
expect(mappedSkus[0].collection).to.equal("22zomer")
|
|
174
|
+
expect(mappedSkus[1].collection).to.equal("22zomer")
|
|
175
|
+
expect(mappedSkus[2].collection).to.equal("22zomer")
|
|
176
|
+
expect(mappedSkus[3].collection).to.equal("22zomer")
|
|
177
|
+
expect(mappedSkus[4].collection).to.equal("22zomer")
|
|
178
|
+
expect(mappedSkus[5].collection).to.equal("22zomer")
|
|
179
|
+
expect(mappedSkus[6].collection).to.equal("22summer")
|
|
180
|
+
expect(mappedSkus[7].collection).to.equal("22summer")
|
|
181
|
+
expect(mappedSkus[8].collection).to.equal("22summer")
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it("returns fully mapped skus on a full mapping", function () {
|
|
185
|
+
const mappedSkus = applyPropertyMapping(skus, fullMapping)
|
|
186
|
+
expect(mappedSkus[0].colorFamily).to.equal("Wit")
|
|
187
|
+
expect(mappedSkus[1].colorFamily).to.equal("Wit")
|
|
188
|
+
expect(mappedSkus[2].colorFamily).to.equal("Wit")
|
|
189
|
+
expect(mappedSkus[3].colorFamily).to.equal("Blauw")
|
|
190
|
+
expect(mappedSkus[4].colorFamily).to.equal("Blauw")
|
|
191
|
+
expect(mappedSkus[5].colorFamily).to.equal("Blauw")
|
|
192
|
+
expect(mappedSkus[6].colorFamily).to.equal("Blue")
|
|
193
|
+
expect(mappedSkus[7].colorFamily).to.equal("Blue")
|
|
194
|
+
expect(mappedSkus[8].colorFamily).to.equal("Blue")
|
|
195
|
+
|
|
196
|
+
expect(mappedSkus[0].collection).to.equal("22zomer")
|
|
197
|
+
expect(mappedSkus[1].collection).to.equal("22zomer")
|
|
198
|
+
expect(mappedSkus[2].collection).to.equal("22zomer")
|
|
199
|
+
expect(mappedSkus[3].collection).to.equal("22zomer")
|
|
200
|
+
expect(mappedSkus[4].collection).to.equal("22zomer")
|
|
201
|
+
expect(mappedSkus[5].collection).to.equal("22zomer")
|
|
202
|
+
expect(mappedSkus[6].collection).to.equal("22zomer")
|
|
203
|
+
expect(mappedSkus[7].collection).to.equal("22zomer")
|
|
204
|
+
expect(mappedSkus[8].collection).to.equal("22zomer")
|
|
205
|
+
})
|
|
206
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { deepCopy } = require("../dist/index")
|
|
2
|
+
const { expect } = require("chai")
|
|
3
|
+
|
|
4
|
+
const input = { foo: { foo: "bar" }, fooArray: [3.14, "foo"] }
|
|
5
|
+
describe("deepCopy function", function () {
|
|
6
|
+
it("should return an exact copy of its nullish input", function () {
|
|
7
|
+
expect(deepCopy()).to.deep.eq(undefined)
|
|
8
|
+
expect(deepCopy(null)).to.deep.eq(null)
|
|
9
|
+
})
|
|
10
|
+
it("should return an object that deepEquals its input", function () {
|
|
11
|
+
expect(deepCopy("1234")).to.deep.eq("1234")
|
|
12
|
+
expect(deepCopy(input)).to.deep.eq(input)
|
|
13
|
+
})
|
|
14
|
+
it("should return a new object", function () {
|
|
15
|
+
expect(deepCopy(input)).to.not.eq(input)
|
|
16
|
+
})
|
|
17
|
+
})
|
package/test/ean13.spec.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { ean13 } = require("../dist/index")
|
|
2
|
-
const {
|
|
2
|
+
const { expect } = require("chai")
|
|
3
3
|
|
|
4
4
|
const should = require("chai").should()
|
|
5
5
|
|
|
@@ -10,6 +10,6 @@ describe("ean13 function", function () {
|
|
|
10
10
|
})
|
|
11
11
|
})
|
|
12
12
|
it("should calculate a valid check digit", function () {
|
|
13
|
-
|
|
13
|
+
expect(ean13("123456789012")).to.equal(1234567890128)
|
|
14
14
|
})
|
|
15
15
|
})
|
package/test/hashBrand.spec.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
const { hashBrand } = require("../dist/index")
|
|
2
|
-
const {
|
|
2
|
+
const { expect } = require("chai")
|
|
3
3
|
|
|
4
4
|
describe("hashBrand function", function () {
|
|
5
5
|
it("should return an empty string on non-string inputs", function () {
|
|
6
|
-
|
|
6
|
+
expect(hashBrand(3)).to.equal("")
|
|
7
7
|
})
|
|
8
8
|
it("should return an empty string on an empty input", function () {
|
|
9
|
-
|
|
9
|
+
expect(hashBrand("")).to.equal("")
|
|
10
10
|
})
|
|
11
11
|
it("should return the input in lowercase without spaces", function () {
|
|
12
|
-
|
|
12
|
+
expect(hashBrand("Marie Jo")).to.equal("mariejo")
|
|
13
13
|
})
|
|
14
14
|
it("should return the input stripped from non characters", function () {
|
|
15
|
-
|
|
15
|
+
expect(hashBrand("Cl ~<>!@#$%^&*():'\"? ean")).to.equal("clean")
|
|
16
16
|
})
|
|
17
17
|
})
|