fast-importer.e2e-spec.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { CreateProductInput, ProductTranslationInput } from '@vendure/common/lib/generated-types';
  2. import { ensureConfigLoaded, FastImporterService, LanguageCode } from '@vendure/core';
  3. import { createTestEnvironment } from '@vendure/testing';
  4. import path from 'path';
  5. import { afterAll, beforeAll, describe, expect, it } from 'vitest';
  6. import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
  7. import { initialData } from '../mock-data/data-sources/initial-data';
  8. import {
  9. GetProductWithVariantsQuery,
  10. GetProductWithVariantsQueryVariables,
  11. } from './graphql/generated-e2e-admin-types';
  12. import { GET_PRODUCT_WITH_VARIANTS } from './graphql/shared-definitions';
  13. describe('FastImporterService resolver', () => {
  14. const { server, adminClient } = createTestEnvironment(testConfig());
  15. let fastImporterService: FastImporterService;
  16. beforeAll(async () => {
  17. await ensureConfigLoaded();
  18. await server.init({
  19. initialData,
  20. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
  21. });
  22. await adminClient.asSuperAdmin();
  23. fastImporterService = server.app.get(FastImporterService);
  24. }, TEST_SETUP_TIMEOUT_MS);
  25. afterAll(async () => {
  26. await server.destroy();
  27. });
  28. it('creates normalized slug', async () => {
  29. const productTranslation: ProductTranslationInput = {
  30. languageCode: LanguageCode.en,
  31. name: 'test product',
  32. slug: 'test product',
  33. description: 'test description',
  34. };
  35. const createProductInput: CreateProductInput = {
  36. translations: [productTranslation],
  37. };
  38. await fastImporterService.initialize();
  39. const productId = await fastImporterService.createProduct(createProductInput);
  40. const { product } = await adminClient.query<
  41. GetProductWithVariantsQuery,
  42. GetProductWithVariantsQueryVariables
  43. >(GET_PRODUCT_WITH_VARIANTS, {
  44. id: productId as string,
  45. });
  46. expect(product?.slug).toMatch('test-product');
  47. });
  48. });