-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathfetch-resources-for-products-test.js
71 lines (61 loc) · 1.97 KB
/
fetch-resources-for-products-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import assert from 'assert';
import fetchResourcesForProducts from '../src/fetch-resources-for-products';
suite('fetch-resources-for-product-test', () => {
test('it returns an empty array when no product is found', () => {
return fetchResourcesForProducts(null).then((result) => {
assert.deepStrictEqual(result, []);
});
});
test('it fetches all pages of images and for a single product', () => {
const imagesArray = ['images'];
const variantsArray = ['variants'];
const fixture = {
images: imagesArray,
variants: variantsArray,
attrs: {
images: imagesArray,
variants: variantsArray
}
};
let fetchAllPagesCounter = 0;
const itemsList = [];
const client = {
fetchAllPages(items) {
fetchAllPagesCounter++;
itemsList.push(items);
return Promise.resolve(['reassigned-array']);
}
};
return fetchResourcesForProducts(fixture, client).then(() => {
assert.equal(fetchAllPagesCounter, 2);
assert.deepEqual(fixture.attrs.images, ['reassigned-array']);
assert.deepEqual(fixture.attrs.variants, ['reassigned-array']);
});
});
test('it fetches all pages of images and for an array of products', () => {
const imagesArray = ['images'];
const variantsArray = ['variants'];
const fixture = {
images: imagesArray,
variants: variantsArray,
attrs: {
images: imagesArray,
variants: variantsArray
}
};
let fetchAllPagesCounter = 0;
const itemsList = [];
const client = {
fetchAllPages(items) {
fetchAllPagesCounter++;
itemsList.push(items);
return Promise.resolve(['reassigned-array']);
}
};
return fetchResourcesForProducts([fixture], client).then(() => {
assert.equal(fetchAllPagesCounter, 2);
assert.deepEqual(fixture.attrs.images, ['reassigned-array']);
assert.deepEqual(fixture.attrs.variants, ['reassigned-array']);
});
});
});