@@ -57,9 +57,12 @@ describe('Engine: fact evaluation', () => {
5757 }
5858 let successSpy = sinon . spy ( )
5959 let failureSpy = sinon . spy ( )
60- function setup ( conditions = baseConditions ( ) , engineOptions = { } ) {
60+ beforeEach ( ( ) => {
6161 successSpy . reset ( )
6262 failureSpy . reset ( )
63+ } )
64+
65+ function setup ( conditions = baseConditions ( ) , engineOptions = { } ) {
6366 engine = engineFactory ( [ ] , engineOptions )
6467 let rule = factories . rule ( { conditions, event } )
6568 engine . addRule ( rule )
@@ -157,14 +160,40 @@ describe('Engine: fact evaluation', () => {
157160 expect ( successSpy ) . to . not . have . been . called ( )
158161 } )
159162
160- it ( 'emits when complex object paths meet the conditions' , async ( ) => {
161- let complexCondition = conditions ( )
162- complexCondition . any [ 0 ] . path = '.address.occupantHistory[0].year'
163- complexCondition . any [ 0 ] . value = 2011
164- complexCondition . any [ 0 ] . operator = 'equal'
165- setup ( complexCondition )
166- await engine . run ( )
167- expect ( successSpy ) . to . have . been . calledWith ( event )
163+ context ( 'complex paths' , ( ) => {
164+ it ( 'correctly interprets "path" when dynamic facts return objects' , async ( ) => {
165+ let complexCondition = conditions ( )
166+ complexCondition . any [ 0 ] . path = '.address.occupantHistory[0].year'
167+ complexCondition . any [ 0 ] . value = 2011
168+ complexCondition . any [ 0 ] . operator = 'equal'
169+ setup ( complexCondition )
170+ await engine . run ( )
171+ expect ( successSpy ) . to . have . been . calledWith ( event )
172+ } )
173+
174+ it ( 'correctly interprets "path" with runtime fact objects' , async ( ) => {
175+ let fact = { x : { y : 1 } , a : 2 }
176+ let conditions = {
177+ all : [ {
178+ fact : 'x' ,
179+ path : '.y' ,
180+ operator : 'equal' ,
181+ value : 1
182+ } ]
183+ }
184+ let event = {
185+ type : 'runtimeEvent'
186+ }
187+
188+ engine = engineFactory ( [ ] )
189+ let rule = factories . rule ( { conditions, event } )
190+ engine . addRule ( rule )
191+ engine . on ( 'success' , successSpy )
192+ engine . on ( 'failure' , failureSpy )
193+ await engine . run ( fact )
194+ expect ( successSpy ) . to . have . been . calledWith ( event )
195+ expect ( failureSpy ) . to . not . have . been . calledWith ( event )
196+ } )
168197 } )
169198
170199 it ( 'does not emit when complex object paths fail the condition' , async ( ) => {
0 commit comments