import.e2e-spec.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. }
  53. assets {
  54. id
  55. name
  56. }
  57. optionGroups {
  58. id
  59. code
  60. name
  61. }
  62. facetValues {
  63. id
  64. name
  65. facet {
  66. id
  67. name
  68. }
  69. }
  70. variants {
  71. id
  72. name
  73. sku
  74. price
  75. taxCategory {
  76. id
  77. name
  78. }
  79. options {
  80. id
  81. code
  82. }
  83. assets {
  84. id
  85. name
  86. }
  87. featuredAsset {
  88. id
  89. name
  90. }
  91. facetValues {
  92. id
  93. code
  94. name
  95. facet {
  96. id
  97. name
  98. }
  99. }
  100. stockOnHand
  101. trackInventory
  102. stockMovements {
  103. items {
  104. ...on StockMovement {
  105. id
  106. type
  107. quantity
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. `,
  116. {
  117. options: {},
  118. },
  119. );
  120. expect(productResult.products.totalItems).toBe(4);
  121. expect(productResult.products.items).toMatchSnapshot();
  122. return;
  123. }, 10000);
  124. });