Bug 13799: Rename t/.../v1/borrowers.t to t/.../v1/patrons.t
[koha.git] / t / db_dependent / api / v1 / patrons.t
blob344cac9a8cc4d540ae6fa1c46dc7f1b89cd46857
1 #!/usr/bin/env perl
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
8 # version.
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.
18 use Modern::Perl;
20 use Test::More tests => 10;
21 use Test::Mojo;
22 use t::lib::TestBuilder;
24 use C4::Auth;
25 use C4::Context;
27 use Koha::Database;
28 use Koha::Borrower;
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({
42 source => 'Borrower',
43 value => {
44 branchcode => $branchcode,
45 categorycode => $categorycode
47 });
49 $t->get_ok('/api/v1/patrons')
50 ->status_is(403);
52 $t->get_ok("/api/v1/patrons/" . $borrower->{ borrowernumber })
53 ->status_is(403);
55 my $loggedinuser = $builder->build({
56 source => 'Borrower',
57 value => {
58 branchcode => $branchcode,
59 categorycode => $categorycode,
60 flags => 16 # borrowers flag
62 });
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());
69 $session->flush;
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'});
74 $t->request_ok($tx)
75 ->status_is(200);
77 $tx = $t->ua->build_tx(GET => "/api/v1/patrons/" . $borrower->{ borrowernumber });
78 $tx->req->cookies({name => 'CGISESSID', value => $session->id});
79 $t->request_ok($tx)
80 ->status_is(200)
81 ->json_is('/borrowernumber' => $borrower->{ borrowernumber })
82 ->json_is('/surname' => $borrower->{ surname });
84 $dbh->rollback;