|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 12; |
20 |
use Test::More tests => 22; |
| 21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
| 22 |
use t::lib::TestBuilder; |
22 |
use t::lib::TestBuilder; |
| 23 |
|
23 |
|
|
Lines 25-30
use C4::Auth;
Link Here
|
| 25 |
use C4::Context; |
25 |
use C4::Context; |
| 26 |
|
26 |
|
| 27 |
use Koha::Database; |
27 |
use Koha::Database; |
|
|
28 |
use Koha::Account::Line; |
| 28 |
|
29 |
|
| 29 |
my $builder = t::lib::TestBuilder->new(); |
30 |
my $builder = t::lib::TestBuilder->new(); |
| 30 |
|
31 |
|
|
Lines 41-46
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
Link Here
|
| 41 |
$t->get_ok('/api/v1/accountlines') |
42 |
$t->get_ok('/api/v1/accountlines') |
| 42 |
->status_is(401); |
43 |
->status_is(401); |
| 43 |
|
44 |
|
|
|
45 |
$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5}) |
| 46 |
->status_is(401); |
| 47 |
|
| 44 |
my $loggedinuser = $builder->build({ |
48 |
my $loggedinuser = $builder->build({ |
| 45 |
source => 'Borrower', |
49 |
source => 'Borrower', |
| 46 |
value => { |
50 |
value => { |
|
Lines 115-118
$json = $t->tx->res->json;
Link Here
|
| 115 |
ok(ref $json eq 'ARRAY', 'response is a JSON array'); |
119 |
ok(ref $json eq 'ARRAY', 'response is a JSON array'); |
| 116 |
ok(scalar @$json == 4, 'response array contains 3 elements'); |
120 |
ok(scalar @$json == 4, 'response array contains 3 elements'); |
| 117 |
|
121 |
|
|
|
122 |
# Editing accountlines tests |
| 123 |
my $put_data = { |
| 124 |
'amount' => -19, |
| 125 |
'amountoutstanding' => -19 |
| 126 |
}; |
| 127 |
|
| 128 |
$tx = $t->ua->build_tx( |
| 129 |
PUT => "/api/v1/accountlines/11224409" |
| 130 |
=> {Accept => '*/*'} |
| 131 |
=> json => $put_data); |
| 132 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
| 133 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
| 134 |
$t->request_ok($tx) |
| 135 |
->status_is(404); |
| 136 |
|
| 137 |
my $accountline_to_edit = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0]; |
| 138 |
|
| 139 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" => json => $put_data); |
| 140 |
$tx->req->cookies({name => 'CGISESSID', value => $borrowersession->id}); |
| 141 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
| 142 |
$t->request_ok($tx) |
| 143 |
->status_is(403); |
| 144 |
|
| 145 |
$tx = $t->ua->build_tx( |
| 146 |
PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" |
| 147 |
=> {Accept => '*/*'} |
| 148 |
=> json => $put_data); |
| 149 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
| 150 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
| 151 |
$t->request_ok($tx) |
| 152 |
->status_is(200); |
| 153 |
|
| 154 |
my $accountline_edited = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber2})->unblessed()->[0]; |
| 155 |
|
| 156 |
is($accountline_edited->{amount}, '-19.000000'); |
| 157 |
is($accountline_edited->{amountoutstanding}, '-19.000000'); |
| 158 |
|
| 159 |
|
| 160 |
# Payment tests |
| 161 |
|
| 118 |
$dbh->rollback; |
162 |
$dbh->rollback; |
| 119 |
- |
|
|