|
261 | 261 | end |
262 | 262 |
|
263 | 263 | describe 'calling the action' do |
264 | | - before(:each) do |
265 | | - allow_any_instance_of(ForestLiana::Ability).to receive(:forest_authorize!) { true } |
266 | | - end |
267 | | - |
268 | 264 | let(:all_records) { false } |
269 | 265 | let(:params) { |
270 | 266 | { |
|
283 | 279 |
|
284 | 280 | describe 'without scopes' do |
285 | 281 | it 'should respond 200 and perform the action' do |
| 282 | + allow_any_instance_of(ForestLiana::Ability).to receive(:forest_authorize!) { true } |
286 | 283 | post '/forest/actions/test', params: JSON.dump(params), headers: headers |
287 | 284 | expect(response.status).to eq(200) |
288 | 285 | expect(JSON.parse(response.body)).to eq({'success' => 'You are OK.'}) |
289 | 286 | end |
| 287 | + |
| 288 | + let(:params) { |
| 289 | + { |
| 290 | + data: { |
| 291 | + attributes: { |
| 292 | + collection_name: 'Island', |
| 293 | + ids: ['1'], |
| 294 | + all_records: all_records, |
| 295 | + smart_action_id: 'Island-Test' |
| 296 | + }, |
| 297 | + type: 'custom-action-requests' |
| 298 | + }, |
| 299 | + timezone: 'Europe/Paris' |
| 300 | + } |
| 301 | + } |
| 302 | + |
| 303 | + describe 'with invalid conditions' do |
| 304 | + it 'should respond a 409' do |
| 305 | + Rails.cache.write('forest.has_permission', true) |
| 306 | + Rails.cache.write('forest.users', {'38' => { 'id' => 38, 'roleId' => 1, 'rendering_id' => '13' }}) |
| 307 | + Rails.cache.write( |
| 308 | + 'forest.collections', |
| 309 | + { |
| 310 | + 'Island' => { |
| 311 | + :actions => |
| 312 | + { |
| 313 | + 'test' => { 'triggerEnabled' => [1], |
| 314 | + 'triggerConditions' => [], |
| 315 | + 'approvalRequired' => [1], |
| 316 | + 'approvalRequiredConditions' => |
| 317 | + [ |
| 318 | + { 'filter' => |
| 319 | + { 'field' => 'id', |
| 320 | + 'value' => 2, |
| 321 | + 'source' => 'data', |
| 322 | + 'operator' => 'foo-greater-than' |
| 323 | + }, |
| 324 | + 'roleId' => 1 |
| 325 | + } |
| 326 | + ], |
| 327 | + } |
| 328 | + } |
| 329 | + } |
| 330 | + } |
| 331 | + ) |
| 332 | + |
| 333 | + post '/forest/actions/test', params: JSON.dump(params), headers: headers |
| 334 | + |
| 335 | + expect(response.status).to eq(409) |
| 336 | + expect(JSON.parse(response.body)).to eq( |
| 337 | + { |
| 338 | + "errors" => [ |
| 339 | + { |
| 340 | + "status" => 409, |
| 341 | + "detail" => "The conditions to trigger this action cannot be verified. Please contact an administrator.", |
| 342 | + "name" => "InvalidActionConditionError" |
| 343 | + } |
| 344 | + ] |
| 345 | + } |
| 346 | + ) |
| 347 | + end |
| 348 | + end |
| 349 | + |
| 350 | + describe 'with unknown action' do |
| 351 | + it 'should respond a 409' do |
| 352 | + Rails.cache.write('forest.has_permission', true) |
| 353 | + Rails.cache.write('forest.users', {'38' => { 'id' => 38, 'roleId' => 1, 'rendering_id' => '13' }}) |
| 354 | + Rails.cache.write( |
| 355 | + 'forest.collections', |
| 356 | + { |
| 357 | + 'Island' => { |
| 358 | + :actions => |
| 359 | + { |
| 360 | + 'test' => { 'triggerEnabled' => [1], |
| 361 | + 'triggerConditions' => [], |
| 362 | + 'approvalRequired' => [1], |
| 363 | + 'approvalRequiredConditions' => |
| 364 | + [ |
| 365 | + { 'filter' => |
| 366 | + { 'field' => 'id', |
| 367 | + 'value' => 2, |
| 368 | + 'source' => 'data', |
| 369 | + 'operator' => 'foo-greater-than' |
| 370 | + }, |
| 371 | + 'roleId' => 1 |
| 372 | + } |
| 373 | + ], |
| 374 | + } |
| 375 | + } |
| 376 | + } |
| 377 | + } |
| 378 | + ) |
| 379 | + |
| 380 | + post '/forest/actions/unknown_action', params: JSON.dump(params), headers: headers |
| 381 | + |
| 382 | + expect(response.status).to eq(409) |
| 383 | + expect(JSON.parse(response.body)).to eq( |
| 384 | + {"errors"=> [{"detail" => "The collection Island doesn't exist", "name" => "collection not found", "status" => 409}]} |
| 385 | + ) |
| 386 | + end |
| 387 | + end |
290 | 388 | end |
291 | 389 |
|
292 | 390 | describe 'with scopes' do |
| 391 | + before(:each) do |
| 392 | + allow_any_instance_of(ForestLiana::Ability).to receive(:forest_authorize!) { true } |
| 393 | + end |
| 394 | + |
293 | 395 | describe 'when record is in scope' do |
294 | 396 | let(:scope_filters) { |
295 | 397 | { |
|
0 commit comments