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

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

Return to bug 13799