Skip to content

Commit

Permalink
fix(typeorm): fix unit tests after fix filters bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDoePlusPlus authored and doug-martin committed Oct 1, 2020
1 parent 6ada4f4 commit 5f50419
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<TestEntity>();

beforeEach(() => {
let index = -1;
(randomString as jest.Mock<any, any>).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(
Expand Down
1 change: 1 addition & 0 deletions packages/query-typeorm/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './randomString';
5 changes: 5 additions & 0 deletions packages/query-typeorm/src/common/randomString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { v4 } from 'uuid';

export function randomString(): string {
return v4().replace(/-/g, '');
}
6 changes: 4 additions & 2 deletions packages/query-typeorm/src/query/sql-comparison.builder.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -38,7 +40,7 @@ export class SQLComparisonBuilder<Entity> {
constructor(readonly comparisonMap: Record<string, string> = SQLComparisonBuilder.DEFAULT_COMPARISON_MAP) {}

private get paramName(): string {
const id = uuid().replace('-', '');
const id = randomString();
const param = `param${id}`;
return param;
}
Expand Down

0 comments on commit 5f50419

Please sign in to comment.