import.e2e-spec.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. const csvFile = path.join(__dirname, 'fixtures', 'product-import.csv');
  21. const result = await client.importProducts(csvFile);
  22. expect(result.importProducts.errors).toEqual([]);
  23. expect(result.importProducts.importedCount).toBe(4);
  24. const productResult = await client.query(gql`
  25. query {
  26. products {
  27. totalItems
  28. items {
  29. id
  30. name
  31. slug
  32. description
  33. featuredAsset {
  34. id
  35. name
  36. }
  37. assets {
  38. id
  39. name
  40. }
  41. optionGroups {
  42. id
  43. code
  44. name
  45. }
  46. variants {
  47. id
  48. name
  49. sku
  50. price
  51. taxCategory {
  52. id
  53. name
  54. }
  55. options {
  56. id
  57. code
  58. }
  59. }
  60. }
  61. }
  62. }
  63. `);
  64. expect(productResult.products.totalItems).toBe(4);
  65. expect(productResult.products.items).toMatchSnapshot();
  66. });
  67. });