fast-importer.e2e-spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
  7. import { initialData } from '../mock-data/data-sources/initial-data';
  8. import { getProductWithVariantsDocument } from './graphql/shared-definitions';
  9. describe('FastImporterService resolver', () => {
  10. const { server, adminClient } = createTestEnvironment(testConfig());
  11. let fastImporterService: FastImporterService;
  12. beforeAll(async () => {
  13. await ensureConfigLoaded();
  14. await server.init({
  15. initialData,
  16. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
  17. });
  18. await adminClient.asSuperAdmin();
  19. fastImporterService = server.app.get(FastImporterService);
  20. }, TEST_SETUP_TIMEOUT_MS);
  21. afterAll(async () => {
  22. await server.destroy();
  23. });
  24. it('creates normalized slug', async () => {
  25. const productTranslation: ProductTranslationInput = {
  26. languageCode: LanguageCode.en,
  27. name: 'test product',
  28. slug: 'test product',
  29. description: 'test description',
  30. };
  31. const createProductInput: CreateProductInput = {
  32. translations: [productTranslation],
  33. };
  34. await fastImporterService.initialize();
  35. const productId = await fastImporterService.createProduct(createProductInput);
  36. const { product } = await adminClient.query(getProductWithVariantsDocument, {
  37. id: productId as string,
  38. });
  39. expect(product?.slug).toMatch('test-product');
  40. });
  41. });