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

(-)a/t/db_dependent/api/v1/biblios.t (-2 / +72 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use utf8;
20
use utf8;
21
use Encode;
21
use Encode;
22
22
23
use Test::More tests => 13;
23
use Test::More tests => 14;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Mojo;
25
use Test::Mojo;
26
use Test::Warn;
26
use Test::Warn;
Lines 35-40 use C4::Circulation qw( AddIssue AddReturn ); Link Here
35
35
36
use Koha::Biblios;
36
use Koha::Biblios;
37
use Koha::Database;
37
use Koha::Database;
38
use Koha::DateUtils qw (dt_from_string);
38
use Koha::Checkouts;
39
use Koha::Checkouts;
39
use Koha::Old::Checkouts;
40
use Koha::Old::Checkouts;
40
41
Lines 656-661 subtest 'get_items_public() tests' => sub { Link Here
656
    $schema->storage->txn_rollback;
657
    $schema->storage->txn_rollback;
657
};
658
};
658
659
660
subtest 'get_bookings() tests' => sub {
661
662
    plan tests => 8;
663
664
    $schema->storage->txn_begin;
665
666
    my $librarian = $builder->build_object(
667
        {
668
            class => 'Koha::Patrons',
669
            value => { flags => 0 }     # no additional permissions
670
        }
671
    );
672
    $builder->build(
673
        {
674
            source => 'UserPermission',
675
            value  => {
676
                borrowernumber => $librarian->borrowernumber,
677
                module_bit     => 1,
678
                code           => 'manage_bookings',
679
            },
680
        }
681
    );
682
    my $password = 'thePassword123';
683
    $librarian->set_password( { password => $password, skip_validation => 1 } );
684
    my $userid = $librarian->userid;
685
686
    my $patron = $builder->build_object(
687
        {
688
            class => 'Koha::Patrons',
689
            value => { flags => 0 }
690
        }
691
    );
692
    $patron->set_password( { password => $password, skip_validation => 1 } );
693
    my $unauth_userid = $patron->userid;
694
695
    my $biblio = $builder->build_sample_biblio();
696
    my $item1  = $builder->build_sample_item( { bookable => 1, biblionumber => $biblio->id } );
697
    my $item2  = $builder->build_sample_item( { bookable => 1, biblionumber => $biblio->id } );
698
699
    $t->get_ok("//$unauth_userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings")
700
      ->status_is(403);
701
702
    $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings")
703
      ->status_is(200)
704
      ->json_is( '' => [], 'No bookings on the biblio' );
705
706
    # One booking
707
    my $start_0   = dt_from_string->subtract( days => 2 )->truncate( to => 'day' );
708
    my $end_0     = dt_from_string->add( days => 4 )->truncate( to => 'day' );
709
    my $booking_0 = $builder->build_object(
710
        {
711
            class => 'Koha::Bookings',
712
            value => {
713
                biblio_id  => $biblio->id,
714
                item_id    => $item1->id,
715
                start_date => $start_0,
716
                end_date   => $end_0
717
            }
718
        }
719
    );
720
721
    my $ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings")
722
      ->status_is(200)
723
      ->tx->res->json;
724
725
    is_deeply( $ret, [ $booking_0->to_api ] );
726
727
    $schema->storage->txn_rollback;
728
};
729
659
subtest 'get_checkouts() tests' => sub {
730
subtest 'get_checkouts() tests' => sub {
660
731
661
    plan tests => 14;
732
    plan tests => 14;
662
- 

Return to bug 35574