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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* tslint:disable: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 { initialData } from '../../../e2e-common/e2e-initial-data';
  13. import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
  14. import { GetProductList } from './graphql/generated-e2e-admin-types';
  15. import { GET_PRODUCT_LIST } from './graphql/shared-definitions';
  16. describe('UuidIdStrategy', () => {
  17. const { server, adminClient } = createTestEnvironment({
  18. ...testConfig,
  19. 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<GetProductList.Query, GetProductList.Variables>(
  34. GET_PRODUCT_LIST,
  35. {
  36. options: {
  37. take: 1,
  38. },
  39. },
  40. );
  41. expect(isV4Uuid(products.items[0].id)).toBe(true);
  42. });
  43. });
  44. /**
  45. * Returns true if the id string matches the format for a v4 UUID.
  46. */
  47. function isV4Uuid(id: string): boolean {
  48. 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);
  49. }