forked from vendure-ecommerce/vendure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.e2e-spec.ts
140 lines (131 loc) · 5.26 KB
/
import.e2e-spec.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import gql from 'graphql-tag';
import path from 'path';
import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
import { TestAdminClient } from './test-client';
import { TestServer } from './test-server';
describe('Import resolver', () => {
const client = new TestAdminClient();
const server = new TestServer();
beforeAll(async () => {
const token = await server.init({
productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-empty.csv'),
customerCount: 0,
});
await client.init();
}, TEST_SETUP_TIMEOUT_MS);
afterAll(async () => {
await server.destroy();
});
it('imports products', async () => {
// TODO: waste a few more hours actually fixing this for real
// Forgive me this abomination of a work-around.
// On the inital run (as in CI), when the sqlite db has just been populated,
// this test will fail due to an "out of memory" exception originating from
// SqljsQueryRunner.ts:79:22, which is part of the findOne() operation on the
// Session repository called from the AuthService.validateSession() method.
// After several hours of fruitless hunting, I did what any desperate JavaScript
// developer would do, and threw in a setTimeout. Which of course "works"...
const timeout = process.env.CI ? 2000 : 1000;
await new Promise(resolve => {
setTimeout(resolve, timeout);
});
const csvFile = path.join(__dirname, 'fixtures', 'product-import.csv');
const result = await client.importProducts(csvFile);
expect(result.importProducts.errors).toEqual([
'Invalid Record Length: header length is 14, got 1 on line 8',
]);
expect(result.importProducts.imported).toBe(4);
expect(result.importProducts.processed).toBe(4);
const productResult = await client.query(
gql`
query GetProducts($options: ProductListOptions) {
products(options: $options) {
totalItems
items {
id
name
slug
description
featuredAsset {
id
name
preview
source
}
assets {
id
name
preview
source
}
optionGroups {
id
code
name
}
facetValues {
id
name
facet {
id
name
}
}
variants {
id
name
sku
price
taxCategory {
id
name
}
options {
id
code
}
assets {
id
name
preview
source
}
featuredAsset {
id
name
preview
source
}
facetValues {
id
code
name
facet {
id
name
}
}
stockOnHand
trackInventory
stockMovements {
items {
... on StockMovement {
id
type
quantity
}
}
}
}
}
}
}
`,
{
options: {},
},
);
expect(productResult.products.totalItems).toBe(4);
expect(productResult.products.items).toMatchSnapshot();
}, 20000);
});