import.e2e-spec.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import gql from 'graphql-tag';
  2. import * as path from 'path';
  3. import { TEST_SETUP_TIMEOUT_MS } from './config/test-config';
  4. import { TestClient } from './test-client';
  5. import { TestServer } from './test-server';
  6. describe('Import resolver', () => {
  7. const client = new TestClient();
  8. const server = new TestServer();
  9. beforeAll(async () => {
  10. const token = await server.init({
  11. productCount: 0,
  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 : 500;
  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. expect(result.importProducts.importedCount).toBe(4);
  36. const productResult = await client.query(
  37. gql`
  38. query GetProducts($options: ProductListOptions) {
  39. products(options: $options) {
  40. totalItems
  41. items {
  42. id
  43. name
  44. slug
  45. description
  46. featuredAsset {
  47. id
  48. name
  49. }
  50. assets {
  51. id
  52. name
  53. }
  54. optionGroups {
  55. id
  56. code
  57. name
  58. }
  59. variants {
  60. id
  61. name
  62. sku
  63. price
  64. taxCategory {
  65. id
  66. name
  67. }
  68. options {
  69. id
  70. code
  71. }
  72. }
  73. }
  74. }
  75. }
  76. `,
  77. {
  78. options: {},
  79. },
  80. );
  81. expect(productResult.products.totalItems).toBe(4);
  82. expect(productResult.products.items).toMatchSnapshot();
  83. return;
  84. }, 10000);
  85. });