Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 22; |
20 |
|
|
|
21 |
use Test::More tests => 37; |
21 |
use Test::Mojo; |
22 |
use Test::Mojo; |
22 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
23 |
|
24 |
|
Lines 45-50
$t->get_ok('/api/v1/accountlines')
Link Here
|
45 |
$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5}) |
46 |
$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5}) |
46 |
->status_is(401); |
47 |
->status_is(401); |
47 |
|
48 |
|
|
|
49 |
$t->post_ok("/api/v1/accountlines/11224408/payment") |
50 |
->status_is(401); |
51 |
|
48 |
my $loggedinuser = $builder->build({ |
52 |
my $loggedinuser = $builder->build({ |
49 |
source => 'Borrower', |
53 |
source => 'Borrower', |
50 |
value => { |
54 |
value => { |
Lines 75-82
my $borrowernumber2 = $borrower2->{borrowernumber};
Link Here
|
75 |
|
79 |
|
76 |
$dbh->do(q| DELETE FROM accountlines |); |
80 |
$dbh->do(q| DELETE FROM accountlines |); |
77 |
$dbh->do(q| |
81 |
$dbh->do(q| |
78 |
INSERT INTO accountlines (borrowernumber, amount, accounttype) |
82 |
INSERT INTO accountlines (borrowernumber, amount, accounttype, amountoutstanding) |
79 |
VALUES (?, 20, 'A'), (?, 40, 'F'), (?, 80, 'F'), (?, 10, 'F') |
83 |
VALUES (?, 20, 'A', 20), (?, 40, 'F', 40), (?, 80, 'F', 80), (?, 10, 'F', 10) |
80 |
|, undef, $borrowernumber, $borrowernumber, $borrowernumber, $borrowernumber2); |
84 |
|, undef, $borrowernumber, $borrowernumber, $borrowernumber, $borrowernumber2); |
81 |
|
85 |
|
82 |
my $session = C4::Auth::get_session(''); |
86 |
my $session = C4::Auth::get_session(''); |
Lines 127-133
my $put_data = {
Link Here
|
127 |
|
131 |
|
128 |
$tx = $t->ua->build_tx( |
132 |
$tx = $t->ua->build_tx( |
129 |
PUT => "/api/v1/accountlines/11224409" |
133 |
PUT => "/api/v1/accountlines/11224409" |
130 |
=> {Accept => '*/*'} |
|
|
131 |
=> json => $put_data); |
134 |
=> json => $put_data); |
132 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
135 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
133 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
136 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
Lines 144-150
$t->request_ok($tx)
Link Here
|
144 |
|
147 |
|
145 |
$tx = $t->ua->build_tx( |
148 |
$tx = $t->ua->build_tx( |
146 |
PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" |
149 |
PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" |
147 |
=> {Accept => '*/*'} |
|
|
148 |
=> json => $put_data); |
150 |
=> json => $put_data); |
149 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
151 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
150 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
152 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
Lines 158-162
is($accountline_edited->{amountoutstanding}, '-19.000000');
Link Here
|
158 |
|
160 |
|
159 |
|
161 |
|
160 |
# Payment tests |
162 |
# Payment tests |
|
|
163 |
$tx = $t->ua->build_tx(POST => "/api/v1/accountlines/4562765765/payment"); |
164 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
165 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
166 |
$t->request_ok($tx) |
167 |
->status_is(404); |
168 |
|
169 |
my $accountline_to_pay = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber, 'amount' => 20})->unblessed()->[0]; |
170 |
$tx = $t->ua->build_tx(POST => "/api/v1/accountlines/$accountline_to_pay->{accountlines_id}/payment"); |
171 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
172 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
173 |
$t->request_ok($tx) |
174 |
->status_is(200); |
175 |
#$t->content_is('toto'); |
176 |
|
177 |
my $accountline_paid = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber, 'amount' => -20})->unblessed()->[0]; |
178 |
ok($accountline_paid); |
179 |
|
180 |
# Partial payment tests |
181 |
my $post_data = { |
182 |
'amount' => 17, |
183 |
'note' => 'Partial payment' |
184 |
}; |
185 |
|
186 |
$tx = $t->ua->build_tx( |
187 |
POST => "/api/v1/accountlines/11224419/payment" |
188 |
=> json => $post_data); |
189 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
190 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
191 |
$t->request_ok($tx) |
192 |
->status_is(404); |
193 |
|
194 |
my $accountline_to_partiallypay = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber, 'amount' => 80})->unblessed()->[0]; |
195 |
|
196 |
$tx = $t->ua->build_tx(POST => "/api/v1/accountlines/$accountline_to_partiallypay->{accountlines_id}/payment" => json => {amount => 'foo'}); |
197 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
198 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
199 |
$t->request_ok($tx) |
200 |
->status_is(400); |
201 |
|
202 |
$tx = $t->ua->build_tx(POST => "/api/v1/accountlines/$accountline_to_partiallypay->{accountlines_id}/payment" => json => $post_data); |
203 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
204 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
205 |
$t->request_ok($tx) |
206 |
->status_is(200); |
207 |
|
208 |
$accountline_to_partiallypay = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber, 'amount' => 80})->unblessed()->[0]; |
209 |
is($accountline_to_partiallypay->{amountoutstanding}, '63.000000'); |
210 |
|
211 |
my $accountline_partiallypaid = Koha::Account::Lines->search({'borrowernumber' => $borrowernumber, 'amount' => -17})->unblessed()->[0]; |
212 |
ok($accountline_partiallypaid); |
161 |
|
213 |
|
162 |
$dbh->rollback; |
214 |
$dbh->rollback; |