@@ -205,9 +205,67 @@ module Ability
205205 expect { smart_action_checker . can_execute? } . to raise_error ( ForestLiana ::Ability ::Exceptions ::TriggerForbidden )
206206 end
207207
208- it 'should raise error when triggerConditions not match' do
208+ it 'should trigger action when approvalRequiredCondition not match but with triggerConditions matched' do
209+ parameters = ActionController ::Parameters . new ( params ) . permit!
210+ action [ 'approvalRequired' ] = [ 1 ]
211+ action [ 'triggerEnabled' ] = [ 1 ]
212+ action [ 'triggerConditions' ] = [
213+ { 'filter' =>
214+ { 'aggregator' => 'and' ,
215+ 'conditions' =>
216+ [
217+ {
218+ 'field' => 'name' ,
219+ 'value' => 'foo' ,
220+ 'source' => 'data' ,
221+ 'operator' => 'equal'
222+ }
223+ ]
224+ } ,
225+ 'roleId' => 1
226+ }
227+ ]
228+ action [ 'approvalRequiredConditions' ] = [
229+ { 'filter' =>
230+ { 'aggregator' => 'and' ,
231+ 'conditions' =>
232+ [
233+ {
234+ 'field' => 'name' ,
235+ 'value' => 'fake island' ,
236+ 'source' => 'data' ,
237+ 'operator' => 'equal'
238+ }
239+ ]
240+ } ,
241+ 'roleId' => 1
242+ }
243+ ]
244+ smart_action_checker = ForestLiana ::Ability ::Permission ::SmartActionChecker . new ( parameters , Island , action , user )
245+
246+ expect ( smart_action_checker . can_execute? ) . to equal true
247+ end
248+
249+ it 'should raise error when approvalRequiredConditions and triggerConditions not match' do
209250 parameters = ActionController ::Parameters . new ( params ) . permit!
210251 action [ 'approvalRequired' ] = [ 1 ]
252+ action [ 'triggerEnabled' ] = [ 1 ]
253+ action [ 'triggerConditions' ] = [
254+ { 'filter' =>
255+ { 'aggregator' => 'and' ,
256+ 'conditions' =>
257+ [
258+ {
259+ 'field' => 'name' ,
260+ 'value' => 'fake island' ,
261+ 'source' => 'data' ,
262+ 'operator' => 'equal'
263+ }
264+ ]
265+ } ,
266+ 'roleId' => 1
267+ }
268+ ]
211269 action [ 'approvalRequiredConditions' ] = [
212270 { 'filter' =>
213271 { 'aggregator' => 'and' ,
0 commit comments