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

(-)a/t/db_dependent/api/v1/patrons_holds.t (-1 / +82 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
use Test::Mojo;
22
use Test::Warn;
23
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
26
27
use Koha::Database;
28
use Koha::Hold;
29
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
my $t = Test::Mojo->new('Koha::REST::V1');
34
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
35
t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 );
36
37
subtest 'list() tests' => sub {
38
    plan tests => 15;
39
40
    $schema->storage->txn_begin;
41
42
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
43
    my $password = 'thePassword123';
44
    $patron->set_password({ password => $password, skip_validation => 1 });
45
    my $userid = $patron->userid;
46
    my $patron_id = $patron->borrowernumber;
47
48
    $t->get_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/holds")
49
      ->status_is( 200 )
50
      ->json_is( [] );
51
52
    my $biblio1 = $builder->build_sample_biblio;
53
54
    my $hold = Koha::Hold->new(
55
        {
56
            borrowernumber => $patron->borrowernumber,
57
            biblionumber   => $biblio1->biblionumber,
58
        }
59
    )->store;
60
61
    $t->get_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/holds")
62
      ->status_is( 200 )
63
      ->json_is( '/0/hold_id', $hold->reserve_id );
64
65
    $t->get_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/holds?old=true")
66
      ->status_is( 200 )
67
      ->json_is( [] );
68
69
    $hold->cancel();
70
71
72
73
    $t->get_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/holds?old=true")
74
      ->status_is( 200 )
75
      ->json_is( '/0/hold_id', $hold->reserve_id );
76
77
    $t->get_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/holds")
78
      ->status_is( 200 )
79
      ->json_is( [] );
80
81
    $schema->storage->txn_rollback;
82
};

Return to bug 20936