Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): oData queries with input filter #656

Merged
merged 8 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,62 @@ describe('GridOdataService', () => {
expect(query).toBe(expectation);
});

it('should return a query to filter a search value between an inclusive range of numbers using the 2 dots (..) separator, the "RangeInclusive" operator and the range has an unbounded end', () => {
const expectation = `$top=10&$filter=(Duration ge 5)`;
const mockColumnDuration = { id: 'duration', field: 'duration', type: FieldType.number } as Column;
const mockColumnFilters = {
duration: { columnId: 'duration', columnDef: mockColumnDuration, searchTerms: ['5..'], operator: 'RangeInclusive' },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query to filter a search value between an inclusive range of numbers using the 2 dots (..) separator, the "RangeInclusive" operator and the range has an unbounded begin', () => {
const expectation = `$top=10&$filter=(Duration le 5)`;
const mockColumnDuration = { id: 'duration', field: 'duration', type: FieldType.number } as Column;
const mockColumnFilters = {
duration: { columnId: 'duration', columnDef: mockColumnDuration, searchTerms: ['..5'], operator: 'RangeInclusive' },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query to filter a search value between an inclusive range of numbers using the 2 dots (..) separator, the "RangeExclusive" operator and the range has an unbounded end', () => {
const expectation = `$top=10&$filter=(Duration gt 5)`;
const mockColumnDuration = { id: 'duration', field: 'duration', type: FieldType.number } as Column;
const mockColumnFilters = {
duration: { columnId: 'duration', columnDef: mockColumnDuration, searchTerms: ['5..'], operator: 'RangeExclusive' },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query to filter a search value between an inclusive range of numbers using the 2 dots (..) separator, the "RangeExclusive" operator and the range has an unbounded begin', () => {
const expectation = `$top=10&$filter=(Duration lt 5)`;
const mockColumnDuration = { id: 'duration', field: 'duration', type: FieldType.number } as Column;
const mockColumnFilters = {
duration: { columnId: 'duration', columnDef: mockColumnDuration, searchTerms: ['..5'], operator: 'RangeExclusive' },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query to filter a search value between an exclusive range of numbers using 2 search terms and the "RangeExclusive" operator', () => {
const expectation = `$top=10&$filter=(substringof('abc', Company) and (Duration gt 5 and Duration lt 22))`;
const mockColumnCompany = { id: 'company', field: 'company' } as Column;
Expand Down Expand Up @@ -1423,9 +1479,9 @@ describe('GridOdataService', () => {
expect(currentFilters).toEqual(presetFilters);
});

it('should return a query with a filter with range of numbers with decimals when the preset is a filter range with 3 dots (...) separator', () => {
it('should return a query with a filter with range of numbers with decimals when the preset is a filter range with 2 dots (..) separator and range ends with a fraction', () => {
serviceOptions.columnDefinitions = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'duration', field: 'duration', type: FieldType.number }];
const expectation = `$top=10&$filter=(Duration ge 0.5 and Duration le .88)`;
const expectation = `$top=10&$filter=(Duration ge 0.5 and Duration le 0.88)`;
const presetFilters = [
{ columnId: 'duration', searchTerms: ['0.5...88'] },
] as CurrentFilter[];
Expand Down Expand Up @@ -1539,6 +1595,48 @@ describe('GridOdataService', () => {
expect(query).toBe(expectation);
expect(currentFilters).toEqual(presetFilters);
});

it('should return a query to filter a search value with "decimalInputSeparators" set', () => {
const expectation = `$filter=(Duration eq 10.22)`;
const mockColumnDuration = { id: 'duration', field: 'duration', type: FieldType.number, filter: { params: { decimalInputSeparators: ',.' }} } as Column;
const mockColumnFilters = {
duration: { columnId: 'duration', columnDef: mockColumnDuration, searchTerms: ['10,22'] },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query to filter a search value with a fraction of a number that is missing a leading 0', () => {
const expectation = `$filter=(Duration eq 0.22)`;
const mockColumnDuration = { id: 'duration', field: 'duration', type: FieldType.number } as Column;
jr01 marked this conversation as resolved.
Show resolved Hide resolved
const mockColumnFilters = {
duration: { columnId: 'duration', columnDef: mockColumnDuration, searchTerms: ['.22'] },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});

it('should return a query to filter a search value with a number that contains invalid characters', () => {
const expectation = `$filter=(Duration eq -22)`;
const mockColumnDuration = { id: 'duration', field: 'duration', type: FieldType.number } as Column;
const mockColumnFilters = {
duration: { columnId: 'duration', columnDef: mockColumnDuration, searchTerms: ['-2a2'] },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(query).toBe(expectation);
});
});
});

Expand Down
Loading