import _ from 'lodash' ; import { MustCondition , shouldBeOneOf , mustBeAllOf , matchesClauses } from './query_clauses' ; describe ( 'matchesClauses' , ( ) => { test ( 'merges multiple types of Bool Clauses into one' , ( ) => { const TaskWithSchedule = { exists : { field : 'task.schedule' } , } ; const IdleTaskWithExpiredRunAt = { bool : { must : [ { term : { 'task.status' : 'idle' } } , { range : { 'task.runAt' : { lte : 'now' } } } ] , } , } ; const RunningTask = { bool : { must : [ { term : { 'task.status' : 'running' } } ] , } , } ; expect ( matchesClauses ( mustBeAllOf ( TaskWithSchedule ) , shouldBeOneOf ( RunningTask , IdleTaskWithExpiredRunAt ) ) ) . toMatchObject ( { bool : { must : [ TaskWithSchedule ] , should : [ RunningTask , IdleTaskWithExpiredRunAt ] , } , } ) ; } ) ; } ) ;