import.e2e-spec.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import gql from 'graphql-tag';
  2. import path from 'path';
  3. import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
  4. import { TestAdminClient } from './test-client';
  5. import { TestServer } from './test-server';
  6. describe('Import resolver', () => {
  7. const client = new TestAdminClient();
  8. const server = new TestServer();
  9. beforeAll(async () => {
  10. const token = await server.init(
  11. {
  12. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-empty.csv'),
  13. customerCount: 0,
  14. },
  15. {
  16. customFields: {
  17. Product: [{ type: 'string', name: 'pageType' }],
  18. ProductVariant: [{ type: 'int', name: 'weight' }],
  19. },
  20. },
  21. );
  22. await client.init();
  23. }, TEST_SETUP_TIMEOUT_MS);
  24. afterAll(async () => {
  25. await server.destroy();
  26. });
  27. it('imports products', async () => {
  28. // TODO: waste a few more hours actually fixing this for real
  29. // Forgive me this abomination of a work-around.
  30. // On the inital run (as in CI), when the sqlite db has just been populated,
  31. // this test will fail due to an "out of memory" exception originating from
  32. // SqljsQueryRunner.ts:79:22, which is part of the findOne() operation on the
  33. // Session repository called from the AuthService.validateSession() method.
  34. // After several hours of fruitless hunting, I did what any desperate JavaScript
  35. // developer would do, and threw in a setTimeout. Which of course "works"...
  36. const timeout = process.env.CI ? 2000 : 1000;
  37. await new Promise(resolve => {
  38. setTimeout(resolve, timeout);
  39. });
  40. const csvFile = path.join(__dirname, 'fixtures', 'product-import.csv');
  41. const result = await client.importProducts(csvFile);
  42. expect(result.importProducts.errors).toEqual([
  43. 'Invalid Record Length: header length is 16, got 1 on line 8',
  44. ]);
  45. expect(result.importProducts.imported).toBe(4);
  46. expect(result.importProducts.processed).toBe(4);
  47. const productResult = await client.query(
  48. gql`
  49. query GetProducts($options: ProductListOptions) {
  50. products(options: $options) {
  51. totalItems
  52. items {
  53. id
  54. name
  55. slug
  56. description
  57. featuredAsset {
  58. id
  59. name
  60. preview
  61. source
  62. }
  63. assets {
  64. id
  65. name
  66. preview
  67. source
  68. }
  69. optionGroups {
  70. id
  71. code
  72. name
  73. }
  74. facetValues {
  75. id
  76. name
  77. facet {
  78. id
  79. name
  80. }
  81. }
  82. customFields {
  83. pageType
  84. }
  85. variants {
  86. id
  87. name
  88. sku
  89. price
  90. taxCategory {
  91. id
  92. name
  93. }
  94. options {
  95. id
  96. code
  97. }
  98. assets {
  99. id
  100. name
  101. preview
  102. source
  103. }
  104. featuredAsset {
  105. id
  106. name
  107. preview
  108. source
  109. }
  110. facetValues {
  111. id
  112. code
  113. name
  114. facet {
  115. id
  116. name
  117. }
  118. }
  119. stockOnHand
  120. trackInventory
  121. stockMovements {
  122. items {
  123. ... on StockMovement {
  124. id
  125. type
  126. quantity
  127. }
  128. }
  129. }
  130. customFields {
  131. weight
  132. }
  133. }
  134. }
  135. }
  136. }
  137. `,
  138. {
  139. options: {},
  140. },
  141. );
  142. expect(productResult.products.totalItems).toBe(4);
  143. expect(productResult.products.items).toMatchSnapshot();
  144. }, 20000);
  145. });