Lines 19-24
use Modern::Perl;
Link Here
|
19 |
|
19 |
|
20 |
use Test::More tests => 10; |
20 |
use Test::More tests => 10; |
21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
|
|
22 |
use t::lib::TestBuilder; |
22 |
|
23 |
|
23 |
use C4::Auth; |
24 |
use C4::Auth; |
24 |
use C4::Context; |
25 |
use C4::Context; |
Lines 26-31
use C4::Context;
Link Here
|
26 |
use Koha::Database; |
27 |
use Koha::Database; |
27 |
use Koha::Borrower; |
28 |
use Koha::Borrower; |
28 |
|
29 |
|
|
|
30 |
my $builder = t::lib::TestBuilder->new(); |
31 |
|
29 |
my $dbh = C4::Context->dbh; |
32 |
my $dbh = C4::Context->dbh; |
30 |
$dbh->{AutoCommit} = 0; |
33 |
$dbh->{AutoCommit} = 0; |
31 |
$dbh->{RaiseError} = 1; |
34 |
$dbh->{RaiseError} = 1; |
Lines 33-64
$dbh->{RaiseError} = 1;
Link Here
|
33 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
36 |
$ENV{REMOTE_ADDR} = '127.0.0.1'; |
34 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
37 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
35 |
|
38 |
|
36 |
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); |
39 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
37 |
my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); |
40 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
38 |
|
41 |
my $borrower = $builder->build({ |
39 |
my $borrower = Koha::Borrower->new; |
42 |
source => 'Borrower', |
40 |
$borrower->categorycode( $categorycode ); |
43 |
value => { |
41 |
$borrower->branchcode( $branchcode ); |
44 |
branchcode => $branchcode, |
42 |
$borrower->surname("Test Surname"); |
45 |
categorycode => $categorycode |
43 |
$borrower->store; |
46 |
} |
44 |
my $borrowernumber = $borrower->borrowernumber; |
47 |
}); |
45 |
|
48 |
|
46 |
$t->get_ok('/api/v1/borrowers') |
49 |
$t->get_ok('/api/v1/borrowers') |
47 |
->status_is(403); |
50 |
->status_is(403); |
48 |
|
51 |
|
49 |
$t->get_ok("/api/v1/borrowers/$borrowernumber") |
52 |
$t->get_ok("/api/v1/borrowers/" . $borrower->{ borrowernumber }) |
50 |
->status_is(403); |
53 |
->status_is(403); |
51 |
|
54 |
|
52 |
my $loggedinuser = Koha::Borrower->new; |
55 |
my $loggedinuser = $builder->build({ |
53 |
$loggedinuser->categorycode($categorycode); |
56 |
source => 'Borrower', |
54 |
$loggedinuser->branchcode($branchcode); |
57 |
value => { |
55 |
$loggedinuser->userid('test_rest_api_user'); |
58 |
branchcode => $branchcode, |
56 |
$loggedinuser->flags(16); # flags for 'borrowers' permission only |
59 |
categorycode => $categorycode, |
57 |
$loggedinuser->store; |
60 |
flags => 16 # borrowers flag |
|
|
61 |
} |
62 |
}); |
58 |
|
63 |
|
59 |
my $session = C4::Auth::get_session(''); |
64 |
my $session = C4::Auth::get_session(''); |
60 |
$session->param('number', $loggedinuser->borrowernumber); |
65 |
$session->param('number', $loggedinuser->{ borrowernumber }); |
61 |
$session->param('id', $loggedinuser->userid); |
66 |
$session->param('id', $loggedinuser->{ userid }); |
62 |
$session->param('ip', '127.0.0.1'); |
67 |
$session->param('ip', '127.0.0.1'); |
63 |
$session->param('lasttime', time()); |
68 |
$session->param('lasttime', time()); |
64 |
$session->flush; |
69 |
$session->flush; |
Lines 69-79
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
Link Here
|
69 |
$t->request_ok($tx) |
74 |
$t->request_ok($tx) |
70 |
->status_is(200); |
75 |
->status_is(200); |
71 |
|
76 |
|
72 |
$tx = $t->ua->build_tx(GET => "/api/v1/borrowers/$borrowernumber"); |
77 |
$tx = $t->ua->build_tx(GET => "/api/v1/borrowers/" . $borrower->{ borrowernumber }); |
73 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
78 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
74 |
$t->request_ok($tx) |
79 |
$t->request_ok($tx) |
75 |
->status_is(200) |
80 |
->status_is(200) |
76 |
->json_is('/borrowernumber' => $borrowernumber) |
81 |
->json_is('/borrowernumber' => $borrower->{ borrowernumber }) |
77 |
->json_is('/surname' => "Test Surname"); |
82 |
->json_is('/surname' => $borrower->{ surname }); |
78 |
|
83 |
|
79 |
$dbh->rollback; |
84 |
$dbh->rollback; |
80 |
- |
|
|