3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Test::More tests => 10;
22 use t::lib::TestBuilder;
30 my $builder = t::lib::TestBuilder->new();
32 my $dbh = C4::Context->dbh;
33 $dbh->{AutoCommit} = 0;
34 $dbh->{RaiseError} = 1;
36 $ENV{REMOTE_ADDR} = '127.0.0.1';
37 my $t = Test::Mojo->new('Koha::REST::V1');
39 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
40 my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
41 my $borrower = $builder->build({
44 branchcode => $branchcode,
45 categorycode => $categorycode
49 $t->get_ok('/api/v1/patrons')
52 $t->get_ok("/api/v1/patrons/" . $borrower->{ borrowernumber })
55 my $loggedinuser = $builder->build({
58 branchcode => $branchcode,
59 categorycode => $categorycode,
60 flags => 16 # borrowers flag
64 my $session = C4::Auth::get_session('');
65 $session->param('number', $loggedinuser->{ borrowernumber });
66 $session->param('id', $loggedinuser->{ userid });
67 $session->param('ip', '127.0.0.1');
68 $session->param('lasttime', time());
71 my $tx = $t->ua->build_tx(GET => '/api/v1/patrons');
72 $tx->req->cookies({name => 'CGISESSID', value => $session->id});
73 $tx->req->env({REMOTE_ADDR => '127.0.0.1'});
77 $tx = $t->ua->build_tx(GET => "/api/v1/patrons/" . $borrower->{ borrowernumber });
78 $tx->req->cookies({name => 'CGISESSID', value => $session->id});
81 ->json_is('/borrowernumber' => $borrower->{ borrowernumber })
82 ->json_is('/surname' => $borrower->{ surname });