| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /* tslint:disable:no-non-null-assertion */
- import { UuidIdStrategy } from '@vendure/core';
- import { createTestEnvironment } from '@vendure/testing';
- import path from 'path';
- import { initialData } from '../../../e2e-common/e2e-initial-data';
- import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
- import '../src/index';
- import { GetProductList } from './graphql/generated-e2e-admin-types';
- import { GET_PRODUCT_LIST } from './graphql/shared-definitions';
- // This import is here to simulate the behaviour of
- // the package end-user importing symbols from the
- // @vendure/core barrel file. Doing so will then cause the
- // recusrsive evaluation of all imported files. This tests
- // the resilience of the id strategy implementation to the
- // order of file evaluation.
- describe('UuidIdStrategy', () => {
- const { server, adminClient } = createTestEnvironment({
- ...testConfig,
- entityIdStrategy: new UuidIdStrategy(),
- });
- beforeAll(async () => {
- await server.init({
- dataDir: path.join(__dirname, '__data__'),
- initialData,
- productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
- customerCount: 1,
- });
- await adminClient.asSuperAdmin();
- }, TEST_SETUP_TIMEOUT_MS);
- afterAll(async () => {
- await server.destroy();
- });
- it('uses uuids', async () => {
- const { products } = await adminClient.query<GetProductList.Query, GetProductList.Variables>(
- GET_PRODUCT_LIST,
- {
- options: {
- take: 1,
- },
- },
- );
- expect(isV4Uuid(products.items[0].id)).toBe(true);
- });
- });
- /**
- * Returns true if the id string matches the format for a v4 UUID.
- */
- function isV4Uuid(id: string): boolean {
- 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);
- }
|