|
| 1 | +import { attribute } from './attribute.function' |
| 2 | +import { mergeConditions } from './merge-conditions.function' |
| 3 | + |
| 4 | +describe('mergeCondition statements', () => { |
| 5 | + test('no redundant parentheses for single condition', () => { |
| 6 | + const conditionDefinitionFns = [attribute('name').beginsWith('sample')] |
| 7 | + |
| 8 | + const conditions = mergeConditions('OR', conditionDefinitionFns) |
| 9 | + const expression = conditions(undefined, undefined) |
| 10 | + expect(expression.statement).toEqual('begins_with (#name, :name)') |
| 11 | + }) |
| 12 | + |
| 13 | + test('no redundant parentheses for multiple condition', () => { |
| 14 | + const conditionDefinitionFns = [attribute('name').beginsWith('sample'), attribute('fullName').beginsWith('sample')] |
| 15 | + |
| 16 | + const conditions = mergeConditions('OR', conditionDefinitionFns) |
| 17 | + const expression = conditions(undefined, undefined) |
| 18 | + |
| 19 | + expect(expression.statement).toEqual('(begins_with (#name, :name) OR begins_with (#fullName, :fullName))') |
| 20 | + }) |
| 21 | + |
| 22 | + test('no redundant parentheses for single condition combined', () => { |
| 23 | + const conditionDefinitionFns = [attribute('name').beginsWith('sample'), attribute('fullName').beginsWith('sample')] |
| 24 | + |
| 25 | + const conditions = mergeConditions('OR', conditionDefinitionFns) |
| 26 | + const andConditions = mergeConditions('AND', [conditions]) |
| 27 | + const expression = andConditions(undefined, undefined) |
| 28 | + expect(expression.statement).toEqual('(begins_with (#name, :name) OR begins_with (#fullName, :fullName))') |
| 29 | + }) |
| 30 | +}) |
0 commit comments