import.e2e-spec.ts 5.3 KB

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