diff --git a/packages/query-typeorm/__tests__/query/sql-comparison.builder.spec.ts b/packages/query-typeorm/__tests__/query/sql-comparison.builder.spec.ts index 9ff1aeaac..2e990190c 100644 --- a/packages/query-typeorm/__tests__/query/sql-comparison.builder.spec.ts +++ b/packages/query-typeorm/__tests__/query/sql-comparison.builder.spec.ts @@ -1,10 +1,21 @@ import { CommonFieldComparisonBetweenType } from '@nestjs-query/core'; import { TestEntity } from '../__fixtures__/test.entity'; import { SQLComparisonBuilder } from '../../src/query'; +import { randomString } from '../../src/common'; + +jest.mock('../../src/common/randomString', () => ({ randomString: jest.fn() })); describe('SQLComparisonBuilder', (): void => { const createSQLComparisonBuilder = () => new SQLComparisonBuilder(); + beforeEach(() => { + let index = -1; + (randomString as jest.Mock).mockImplementation(() => { + index += 1; + return index.toString(); + }); + }); + it('should throw an error for an invalid comparison type', () => { // @ts-ignore expect(() => createSQLComparisonBuilder().build('stringType', 'bad', 'foo', 'TestEntity')).toThrow( diff --git a/packages/query-typeorm/src/common/index.ts b/packages/query-typeorm/src/common/index.ts new file mode 100644 index 000000000..02e438c20 --- /dev/null +++ b/packages/query-typeorm/src/common/index.ts @@ -0,0 +1 @@ +export * from './randomString'; diff --git a/packages/query-typeorm/src/common/randomString.ts b/packages/query-typeorm/src/common/randomString.ts new file mode 100644 index 000000000..4082e6394 --- /dev/null +++ b/packages/query-typeorm/src/common/randomString.ts @@ -0,0 +1,5 @@ +import { v4 } from 'uuid'; + +export function randomString(): string { + return v4().replace(/-/g, ''); +} diff --git a/packages/query-typeorm/src/query/sql-comparison.builder.ts b/packages/query-typeorm/src/query/sql-comparison.builder.ts index a23e84d61..8e3e854c7 100644 --- a/packages/query-typeorm/src/query/sql-comparison.builder.ts +++ b/packages/query-typeorm/src/query/sql-comparison.builder.ts @@ -1,6 +1,8 @@ import { CommonFieldComparisonBetweenType, FilterComparisonOperators } from '@nestjs-query/core'; import { ObjectLiteral } from 'typeorm'; -import { v4 as uuid } from 'uuid'; + +import { randomString } from '../common'; + /** * @internal */ @@ -38,7 +40,7 @@ export class SQLComparisonBuilder { constructor(readonly comparisonMap: Record = SQLComparisonBuilder.DEFAULT_COMPARISON_MAP) {} private get paramName(): string { - const id = uuid().replace('-', ''); + const id = randomString(); const param = `param${id}`; return param; }