swell-js 3.10.7 → 3.10.8
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/api.js +1 -1
- package/dist/products.js +5 -1
- package/package.json +1 -1
- package/src/products.js +2 -1
- package/src/products.test.js +68 -0
package/dist/api.js
CHANGED
package/dist/products.js
CHANGED
|
@@ -35,6 +35,10 @@ var cache = require('./cache');
|
|
|
35
35
|
|
|
36
36
|
var attributesApi = require('./attributes');
|
|
37
37
|
|
|
38
|
+
var _require2 = require('lodash'),
|
|
39
|
+
cloneWith = _require2.cloneWith,
|
|
40
|
+
snakeCase = _require2.snakeCase;
|
|
41
|
+
|
|
38
42
|
var OPTIONS;
|
|
39
43
|
|
|
40
44
|
function methods(request, opt) {
|
|
@@ -417,7 +421,7 @@ function getAttributes(products) {
|
|
|
417
421
|
if (!product.attributes[id]) continue;
|
|
418
422
|
var value = product.attributes[id].value;
|
|
419
423
|
var attr = find(attributes, {
|
|
420
|
-
id: id
|
|
424
|
+
id: snakeCase(id)
|
|
421
425
|
});
|
|
422
426
|
|
|
423
427
|
if (attr) {
|
package/package.json
CHANGED
package/src/products.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { reduce, find, uniq, defaultMethods, toSnake, toCamel, isEqual } = require('./utils');
|
|
2
2
|
const cache = require('./cache');
|
|
3
3
|
const attributesApi = require('./attributes');
|
|
4
|
+
const { cloneWith, snakeCase } = require('lodash');
|
|
4
5
|
|
|
5
6
|
let OPTIONS;
|
|
6
7
|
|
|
@@ -277,7 +278,7 @@ function getAttributes(products) {
|
|
|
277
278
|
for (let id in product.attributes) {
|
|
278
279
|
if (!product.attributes[id]) continue;
|
|
279
280
|
const value = product.attributes[id].value;
|
|
280
|
-
let attr = find(attributes, { id });
|
|
281
|
+
let attr = find(attributes, { id: snakeCase(id) });
|
|
281
282
|
if (attr) {
|
|
282
283
|
attr.values = uniq([...attr.values, ...(value instanceof Array ? value : [value])]);
|
|
283
284
|
} else {
|
package/src/products.test.js
CHANGED
|
@@ -36,6 +36,48 @@ const mockProductWithOptions = {
|
|
|
36
36
|
},
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const mockProductsWithAttributes = [
|
|
40
|
+
{
|
|
41
|
+
name: 'Product One',
|
|
42
|
+
attributes: {
|
|
43
|
+
origin: {
|
|
44
|
+
name: 'Origin',
|
|
45
|
+
type: 'select',
|
|
46
|
+
visible: true,
|
|
47
|
+
filterable: true,
|
|
48
|
+
id: 'origin',
|
|
49
|
+
value: 'Honduras',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'Product Two',
|
|
55
|
+
attributes: {
|
|
56
|
+
spacedAttribute: {
|
|
57
|
+
name: 'Spaced Attribute',
|
|
58
|
+
type: 'text',
|
|
59
|
+
visible: true,
|
|
60
|
+
filterable: true,
|
|
61
|
+
id: 'spaced_attribute',
|
|
62
|
+
value: 'One',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'Product Three',
|
|
68
|
+
attributes: {
|
|
69
|
+
spacedAttribute: {
|
|
70
|
+
name: 'Spaced Attribute',
|
|
71
|
+
type: 'text',
|
|
72
|
+
visible: true,
|
|
73
|
+
filterable: true,
|
|
74
|
+
id: 'spaced_attribute',
|
|
75
|
+
value: 'Two',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
|
|
39
81
|
describe('products', () => {
|
|
40
82
|
let methods;
|
|
41
83
|
beforeEach(() => {
|
|
@@ -169,4 +211,30 @@ describe('products', () => {
|
|
|
169
211
|
});
|
|
170
212
|
});
|
|
171
213
|
});
|
|
214
|
+
|
|
215
|
+
describe('attributes', () => {
|
|
216
|
+
it('should return unique key attributes', () => {
|
|
217
|
+
const attributes = methods.attributes(mockProductsWithAttributes);
|
|
218
|
+
expect(attributes).toEqual([
|
|
219
|
+
{
|
|
220
|
+
name: 'Origin',
|
|
221
|
+
type: 'select',
|
|
222
|
+
visible: true,
|
|
223
|
+
filterable: true,
|
|
224
|
+
id: 'origin',
|
|
225
|
+
value: undefined,
|
|
226
|
+
values: ['Honduras'],
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: 'Spaced Attribute',
|
|
230
|
+
type: 'text',
|
|
231
|
+
visible: true,
|
|
232
|
+
filterable: true,
|
|
233
|
+
id: 'spaced_attribute',
|
|
234
|
+
value: undefined,
|
|
235
|
+
values: ['One', 'Two'],
|
|
236
|
+
},
|
|
237
|
+
]);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
172
240
|
});
|