| Lines 17-23
          
      
      
        Link Here | 
        
          | 17 |  | 17 |  | 
        
          | 18 | use Modern::Perl; | 18 | use Modern::Perl; | 
        
          | 19 |  | 19 |  | 
          
            
              | 20 | use Test::More tests => 5; | 20 | use Test::More tests => 6; | 
        
          | 21 | use Test::Mojo; | 21 | use Test::Mojo; | 
        
          | 22 |  | 22 |  | 
        
          | 23 | use t::lib::TestBuilder; | 23 | use t::lib::TestBuilder; | 
  
    | Lines 420-422
          subtest 'delete() tests' => sub {
      
      
        Link Here | 
        
          | 420 |  | 420 |  | 
        
          | 421 |     $schema->storage->txn_rollback; | 421 |     $schema->storage->txn_rollback; | 
        
          | 422 | }; | 422 | }; | 
          
            
              | 423 | -  | 423 |  | 
            
              |  |  | 424 | subtest 'Permissions tests' => sub { | 
            
              | 425 |     plan tests => 11; | 
            
              | 426 |  | 
            
              | 427 |     $schema->storage->txn_begin; | 
            
              | 428 |  | 
            
              | 429 |     my $librarian = $builder->build_object( | 
            
              | 430 |         { | 
            
              | 431 |             class => 'Koha::Patrons', | 
            
              | 432 |             value => { flags => 2**4 }    # 4 = catalogue | 
            
              | 433 |         } | 
            
              | 434 |     ); | 
            
              | 435 |  | 
            
              | 436 |     my $password = 'thePassword123'; | 
            
              | 437 |     $librarian->set_password( { password => $password, skip_validation => 1 } ); | 
            
              | 438 |     my $userid = $librarian->userid; | 
            
              | 439 |  | 
            
              | 440 |     my $patron = $builder->build_object( | 
            
              | 441 |         { | 
            
              | 442 |             class => 'Koha::Patrons', | 
            
              | 443 |             value => { flags => 0 } | 
            
              | 444 |         } | 
            
              | 445 |     ); | 
            
              | 446 |     my $patron_id = $patron->id; | 
            
              | 447 |  | 
            
              | 448 |     my $suggestion = $builder->build_object( | 
            
              | 449 |         { | 
            
              | 450 |             class => 'Koha::Suggestions', | 
            
              | 451 |             value => { suggestedby => $patron_id, STATUS => 'ASKED' } | 
            
              | 452 |         } | 
            
              | 453 |     ); | 
            
              | 454 |     my $suggestion_data = $suggestion->to_api; | 
            
              | 455 |     delete $suggestion_data->{suggestion_id}; | 
            
              | 456 |     $suggestion->delete; | 
            
              | 457 |  | 
            
              | 458 |     # Unauthorized attempt to write | 
            
              | 459 |     $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) | 
            
              | 460 |         ->status_is( 403, 'SWAGGER3.2.1' ); | 
            
              | 461 |  | 
            
              | 462 |     $builder->build( | 
            
              | 463 |         { | 
            
              | 464 |             source => 'UserPermission', | 
            
              | 465 |             value  => { | 
            
              | 466 |                 borrowernumber => $librarian->id, | 
            
              | 467 |                 module_bit     => 12,                     # 12 = suggestions | 
            
              | 468 |                 code           => 'suggestions_create', | 
            
              | 469 |             }, | 
            
              | 470 |         } | 
            
              | 471 |     ); | 
            
              | 472 |  | 
            
              | 473 |     # Authorized attempt to write | 
            
              | 474 |     my $generated_suggestion = | 
            
              | 475 |         $t->post_ok( "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) | 
            
              | 476 |         ->status_is( 201, 'SWAGGER3.2.1' )->header_like( | 
            
              | 477 |         Location => qr|^\/api\/v1\/suggestions\/\d*|, | 
            
              | 478 |         'SWAGGER3.4.1' | 
            
              | 479 |     )->tx->res->json; | 
            
              | 480 |  | 
            
              | 481 |     my $suggestion_id = $generated_suggestion->{suggestion_id}; | 
            
              | 482 |     is_deeply( | 
            
              | 483 |         $generated_suggestion, | 
            
              | 484 |         Koha::Suggestions->find($suggestion_id)->to_api, | 
            
              | 485 |         'The object is returned' | 
            
              | 486 |     ); | 
            
              | 487 |  | 
            
              | 488 |     $t->delete_ok("//$userid:$password@/api/v1/suggestions/$suggestion_id")->status_is(403); | 
            
              | 489 |  | 
            
              | 490 |     $builder->build( | 
            
              | 491 |         { | 
            
              | 492 |             source => 'UserPermission', | 
            
              | 493 |             value  => { | 
            
              | 494 |                 borrowernumber => $librarian->id, | 
            
              | 495 |                 module_bit     => 12,                     # 12 = suggestions | 
            
              | 496 |                 code           => 'suggestions_delete', | 
            
              | 497 |             }, | 
            
              | 498 |         } | 
            
              | 499 |     ); | 
            
              | 500 |  | 
            
              | 501 |     $t->delete_ok("//$userid:$password@/api/v1/suggestions/$suggestion_id")->status_is( 204, 'SWAGGER3.2.4' ) | 
            
              | 502 |         ->content_is( q{}, 'SWAGGER3.3.4' ); | 
            
              | 503 |  | 
            
              | 504 |     $schema->storage->txn_rollback; | 
            
              | 505 | }; |