entity-uuid-strategy.e2e-spec.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* eslint-disable @typescript-eslint/no-non-null-assertion */
  2. import { UuidIdStrategy } from '@vendure/core';
  3. // This import is here to simulate the behaviour of
  4. // the package end-user importing symbols from the
  5. // @vendure/core barrel file. Doing so will then cause the
  6. // recursive evaluation of all imported files. This tests
  7. // the resilience of the id strategy implementation to the
  8. // order of file evaluation.
  9. import '@vendure/core/dist/index';
  10. import { createTestEnvironment } from '@vendure/testing';
  11. import path from 'path';
  12. import { afterAll, beforeAll, describe, expect, it } from 'vitest';
  13. import { initialData } from '../../../e2e-common/e2e-initial-data';
  14. import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
  15. import { getProductListDocument } from './graphql/shared-definitions';
  16. describe('UuidIdStrategy', () => {
  17. const { server, adminClient } = createTestEnvironment({
  18. ...testConfig(),
  19. entityOptions: { entityIdStrategy: new UuidIdStrategy() },
  20. });
  21. beforeAll(async () => {
  22. await server.init({
  23. initialData,
  24. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
  25. customerCount: 1,
  26. });
  27. await adminClient.asSuperAdmin();
  28. }, TEST_SETUP_TIMEOUT_MS);
  29. afterAll(async () => {
  30. await server.destroy();
  31. });
  32. it('uses uuids', async () => {
  33. const { products } = await adminClient.query(getProductListDocument, {
  34. options: {
  35. take: 1,
  36. },
  37. });
  38. expect(isV4Uuid(products.items[0].id)).toBe(true);
  39. });
  40. });
  41. /**
  42. * Returns true if the id string matches the format for a v4 UUID.
  43. */
  44. function isV4Uuid(id: string): boolean {
  45. return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test(id);
  46. }