Skip to content

Commit

Permalink
Move test back into test file
Browse files Browse the repository at this point in the history
  • Loading branch information
lmd59 committed Feb 1, 2024
1 parent 3e6487c commit aab6334
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 59 deletions.
58 changes: 0 additions & 58 deletions src/helpers/elm/QueryFilterParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,61 +1363,3 @@ export function flattenFilters(filter: AnyFilter): AnyFilter[] {
return a;
}
}

describe('Flatten Filters', () => {
test('should pass through standard equals filter', () => {
const equalsFilter: EqualsFilter = {
type: 'equals',
alias: 'R',
attribute: 'attr-0',
value: 'value-0'
};

const flattenedFilters = flattenFilters(equalsFilter);

expect(flattenedFilters).toHaveLength(1);
expect(flattenedFilters[0]).toEqual(equalsFilter);
});

test('should flatten AND filters', () => {
const equalsFilter0: EqualsFilter = {
type: 'equals',
alias: 'R',
attribute: 'attr-0',
value: 'value-0'
};

const equalsFilter1: EqualsFilter = {
type: 'equals',
alias: 'R',
attribute: 'attr-1',
value: 'value-1'
};

const duringFilter: DuringFilter = {
type: 'during',
alias: 'R',
attribute: 'attr-3',
valuePeriod: {
start: '2021-01-01',
end: '2021-12-01'
}
};

const filter: AndFilter = {
type: 'and',
children: [equalsFilter0, duringFilter, equalsFilter1]
};

const flattenedFilters = flattenFilters(filter);

expect(flattenedFilters).toHaveLength(3);
expect(flattenedFilters).toEqual(
expect.arrayContaining([
expect.objectContaining({ ...equalsFilter0 }),
expect.objectContaining({ ...equalsFilter1 }),
expect.objectContaining({ ...duringFilter })
])
);
});
});
61 changes: 60 additions & 1 deletion test/unit/queryFilters/QueryFilterParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
generateDetailedCodeFilter,
generateDetailedDateFilter,
generateDetailedValueFilter,
codeLookup
codeLookup,
flattenFilters
} from '../../../src/helpers/elm/QueryFilterParser';
import { FHIRWrapper } from 'cql-exec-fhir';
import { DateTime, Interval } from 'cql-execution';
Expand Down Expand Up @@ -924,3 +925,61 @@ describe('codeLookup', () => {
expect(codeLookup('Procedure', 'nonsense')).toBeNull();
});
});

describe('Flatten Filters', () => {
test('should pass through standard equals filter', () => {
const equalsFilter: EqualsFilter = {
type: 'equals',
alias: 'R',
attribute: 'attr-0',
value: 'value-0'
};

const flattenedFilters = flattenFilters(equalsFilter);

expect(flattenedFilters).toHaveLength(1);
expect(flattenedFilters[0]).toEqual(equalsFilter);
});

test('should flatten AND filters', () => {
const equalsFilter0: EqualsFilter = {
type: 'equals',
alias: 'R',
attribute: 'attr-0',
value: 'value-0'
};

const equalsFilter1: EqualsFilter = {
type: 'equals',
alias: 'R',
attribute: 'attr-1',
value: 'value-1'
};

const duringFilter: DuringFilter = {
type: 'during',
alias: 'R',
attribute: 'attr-3',
valuePeriod: {
start: '2021-01-01',
end: '2021-12-01'
}
};

const filter: AndFilter = {
type: 'and',
children: [equalsFilter0, duringFilter, equalsFilter1]
};

const flattenedFilters = flattenFilters(filter);

expect(flattenedFilters).toHaveLength(3);
expect(flattenedFilters).toEqual(
expect.arrayContaining([
expect.objectContaining({ ...equalsFilter0 }),
expect.objectContaining({ ...equalsFilter1 }),
expect.objectContaining({ ...duringFilter })
])
);
});
});

0 comments on commit aab6334

Please sign in to comment.