View | Details | Raw Unified | Return to bug 24400
Collapse All | Expand All

(-)a/t/db_dependent/api/v1/items.t (-7 / +33 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Mojo;
24
use Test::Mojo;
25
use Test::Warn;
25
use Test::Warn;
Lines 30-35 use t::lib::Mocks; Link Here
30
use Mojo::JSON qw(encode_json);
30
use Mojo::JSON qw(encode_json);
31
31
32
use C4::Auth;
32
use C4::Auth;
33
use C4::Circulation;
33
use Koha::Items;
34
use Koha::Items;
34
use Koha::Database;
35
use Koha::Database;
35
36
Lines 575-585 subtest 'pickup_locations() tests' => sub { Link Here
575
576
576
subtest 'checkout() tests' => sub {
577
subtest 'checkout() tests' => sub {
577
578
578
    plan tests => 12;
579
    plan tests => 27;
579
580
580
    $schema->storage->txn_begin;
581
    $schema->storage->txn_begin;
581
582
582
    my $item   = $builder->build_sample_item;
583
    my $item   = $builder->build_sample_item;
584
    my $item2  = $builder->build_sample_item;
583
    my $patron = $builder->build_object(
585
    my $patron = $builder->build_object(
584
        {
586
        {
585
            class => 'Koha::Patrons',
587
            class => 'Koha::Patrons',
Lines 606-624 subtest 'checkout() tests' => sub { Link Here
606
608
607
    my $userid = $nonprivilegedpatron->userid;
609
    my $userid = $nonprivilegedpatron->userid;
608
    my $itemid = $item->id;
610
    my $itemid = $item->id;
609
    my $patronid = $patron->id;
611
    my $itemid2 = $item2->id;
612
    my $patronid = $patron->borrowernumber;
610
    my $non_existent_code = $item->itemnumber;
613
    my $non_existent_code = $item->itemnumber;
611
614
612
    $t->get_ok( "//$userid:$password@/api/v1/items/$itemid/checkout/$patronid" )
615
    $t->post_ok( "//$userid:$password@/api/v1/items/$itemid/checkout/$patronid" )
613
      ->status_is(403)
616
      ->status_is(403)
614
      ->json_is(
617
      ->json_is(
615
        '/error' => 'Authorization failure. Missing required permission(s).' );
618
        '/error' => 'Authorization failure. Missing required permission(s).' );
616
619
617
    $t->get_ok( "//$userid:$password@/api/v1/items/" . $non_existent_code )
620
    $t->get_ok( "//$userid:$password@/api/v1/items/" . $non_existent_code )
618
      ->status_is(404)
621
      ->status_is(403)
619
      ->json_is(
622
      ->json_is(
620
        '/error' => 'Item not found' );
623
        '/error' => 'Authorization failure. Missing required permission(s).' );
621
624
625
    $patron->set_password( { password => $password, skip_validation => 1 } );
622
    $userid = $patron->userid;
626
    $userid = $patron->userid;
623
627
624
    $t->get_ok( "//$userid:$password@/api/v1/items?_per_page=10" )
628
    $t->get_ok( "//$userid:$password@/api/v1/items?_per_page=10" )
Lines 632-643 subtest 'checkout() tests' => sub { Link Here
632
      ->status_is(200)
636
      ->status_is(200)
633
      ->json_is( '' => [ $item->to_api ], 'SWAGGER3.3.2');
637
      ->json_is( '' => [ $item->to_api ], 'SWAGGER3.3.2');
634
638
639
    $patron->flags(1)->store;
640
    my $deleted_patron_id = $nonprivilegedpatron->id;
641
    $nonprivilegedpatron->delete;
642
    $t->post_ok( "//$userid:$password@/api/v1/items/$itemid/checkout/$deleted_patron_id" )
643
       ->status_is(400)
644
       ->json_is( '/error' => 'Patron not found' );
645
635
    my $barcode = $item->barcode;
646
    my $barcode = $item->barcode;
636
    $item->delete;
647
    $item->delete;
637
648
649
    $t->post_ok("//$userid:$password@/api/v1/items/$itemid/checkout/$patronid")
650
       ->status_is(404);
651
638
    $t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode )
652
    $t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode )
639
      ->status_is(200)
653
      ->status_is(200)
640
      ->json_is( '' => [] );
654
      ->json_is( '' => [] );
641
655
656
    $t->get_ok( "//$userid:$password@/api/v1/items/" . $non_existent_code )
657
      ->status_is(404)
658
      ->json_is(
659
        '/error' => 'Item not found' );
660
661
    is( $patron->checkouts->count, 0);
662
663
    $t->post_ok( "//$userid:$password@/api/v1/items/$itemid2/checkout/$patronid")
664
       ->status_is(201);
665
666
    is( $patron->checkouts->count, 1);
667
642
    $schema->storage->txn_rollback;
668
    $schema->storage->txn_rollback;
643
};
669
};
644
- 
670

Return to bug 24400