Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 18; |
20 |
use Test::More tests => 46; |
21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
22 |
use t::lib::TestBuilder; |
22 |
use t::lib::TestBuilder; |
23 |
|
23 |
|
Lines 44-49
$t->get_ok('/api/v1/accountlines')
Link Here
|
44 |
$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5}) |
44 |
$t->put_ok("/api/v1/accountlines/11224409" => json => {'amount' => -5}) |
45 |
->status_is(403); |
45 |
->status_is(403); |
46 |
|
46 |
|
|
|
47 |
$t->put_ok("/api/v1/accountlines/11224408/payment") |
48 |
->status_is(403); |
49 |
|
50 |
$t->put_ok("/api/v1/accountlines/11224407/partialpayment" => json => {'amount' => 8}) |
51 |
->status_is(403); |
52 |
|
47 |
my $loggedinuser = $builder->build({ |
53 |
my $loggedinuser = $builder->build({ |
48 |
source => 'Borrower', |
54 |
source => 'Borrower', |
49 |
value => { |
55 |
value => { |
Lines 73-80
my $borrowernumber2 = $borrower2->{borrowernumber};
Link Here
|
73 |
|
79 |
|
74 |
$dbh->do(q| DELETE FROM accountlines |); |
80 |
$dbh->do(q| DELETE FROM accountlines |); |
75 |
$dbh->do(q| |
81 |
$dbh->do(q| |
76 |
INSERT INTO accountlines (borrowernumber, amount, accounttype) |
82 |
INSERT INTO accountlines (borrowernumber, amount, accounttype, amountoutstanding) |
77 |
VALUES (?, 20, 'A'), (?, 40, 'F'), (?, 80, 'F'), (?, 10, 'F') |
83 |
VALUES (?, 20, 'A', 20), (?, 40, 'F', 40), (?, 80, 'F', 80), (?, 10, 'F', 10) |
78 |
|, undef, $borrowernumber, $borrowernumber, $borrowernumber, $borrowernumber2); |
84 |
|, undef, $borrowernumber, $borrowernumber, $borrowernumber, $borrowernumber2); |
79 |
|
85 |
|
80 |
my $session = C4::Auth::get_session(''); |
86 |
my $session = C4::Auth::get_session(''); |
Lines 113-119
my $put_data = {
Link Here
|
113 |
|
119 |
|
114 |
$tx = $t->ua->build_tx( |
120 |
$tx = $t->ua->build_tx( |
115 |
PUT => "/api/v1/accountlines/11224409" |
121 |
PUT => "/api/v1/accountlines/11224409" |
116 |
=> {Accept => '*/*'} |
|
|
117 |
=> json => $put_data); |
122 |
=> json => $put_data); |
118 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
123 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
119 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
124 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
Lines 124-130
my $accountline_to_edit = Koha::Accountlines->search({'borrowernumber' => $borro
Link Here
|
124 |
|
129 |
|
125 |
$tx = $t->ua->build_tx( |
130 |
$tx = $t->ua->build_tx( |
126 |
PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" |
131 |
PUT => "/api/v1/accountlines/$accountline_to_edit->{accountlines_id}" |
127 |
=> {Accept => '*/*'} |
|
|
128 |
=> json => $put_data); |
132 |
=> json => $put_data); |
129 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
133 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
130 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
134 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
Lines 138-142
is($accountline_edited->{amountoutstanding}, '-19.000000');
Link Here
|
138 |
|
142 |
|
139 |
|
143 |
|
140 |
# Payment tests |
144 |
# Payment tests |
|
|
145 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/4562765765/payment"); |
146 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
147 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
148 |
$t->request_ok($tx) |
149 |
->status_is(404); |
150 |
|
151 |
my $accountline_to_pay = Koha::Accountlines->search({'borrowernumber' => $borrowernumber, 'amount' => 20})->unblessed()->[0]; |
152 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$accountline_to_pay->{accountlines_id}/payment"); |
153 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
154 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
155 |
$t->request_ok($tx) |
156 |
->status_is(200); |
157 |
|
158 |
my $accountline_payed = Koha::Accountlines->search({'borrowernumber' => $borrowernumber, 'amount' => -20})->unblessed()->[0]; |
159 |
ok($accountline_payed); |
160 |
|
161 |
# Partial payment tests |
162 |
$put_data = { |
163 |
'amount' => 17, |
164 |
'note' => 'Partial payment' |
165 |
}; |
166 |
|
167 |
$tx = $t->ua->build_tx( |
168 |
PUT => "/api/v1/accountlines/11224419/partialpayment" |
169 |
=> json => $put_data); |
170 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
171 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
172 |
$t->request_ok($tx) |
173 |
->status_is(404); |
174 |
|
175 |
my $accountline_to_partiallypay = Koha::Accountlines->search({'borrowernumber' => $borrowernumber, 'amount' => 80})->unblessed()->[0]; |
176 |
|
177 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$accountline_to_partiallypay->{accountlines_id}/partialpayment" => json => {amount => 'foo'}); |
178 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
179 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
180 |
$t->request_ok($tx) |
181 |
->status_is(400); |
182 |
|
183 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$accountline_to_partiallypay->{accountlines_id}/partialpayment" => json => $put_data); |
184 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
185 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
186 |
$t->request_ok($tx) |
187 |
->status_is(200); |
188 |
|
189 |
$accountline_to_partiallypay = Koha::Accountlines->search({'borrowernumber' => $borrowernumber, 'amount' => 80})->unblessed()->[0]; |
190 |
is($accountline_to_partiallypay->{amountoutstanding}, '63.000000'); |
191 |
|
192 |
my $accountline_partiallypayed = Koha::Accountlines->search({'borrowernumber' => $borrowernumber, 'amount' => 17})->unblessed()->[0]; |
193 |
ok($accountline_partiallypayed); |
194 |
|
195 |
# Pay amount tests |
196 |
my $borrower3 = $builder->build({ |
197 |
source => 'Borrower', |
198 |
value => { |
199 |
branchcode => $branchcode, |
200 |
categorycode => $categorycode, |
201 |
} |
202 |
}); |
203 |
my $borrowernumber3 = $borrower3->{borrowernumber}; |
204 |
|
205 |
$dbh->do(q| |
206 |
INSERT INTO accountlines (borrowernumber, amount, accounttype, amountoutstanding) |
207 |
VALUES (?, 26, 'A', 26) |
208 |
|, undef, $borrowernumber3); |
209 |
|
210 |
$t->put_ok("/api/v1/accountlines/$borrowernumber3/amountpayment" => json => {'amount' => 8}) |
211 |
->status_is(403); |
212 |
|
213 |
my $put_data2 = { |
214 |
'amount' => 24, |
215 |
'note' => 'Partial payment' |
216 |
}; |
217 |
|
218 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/8789798797/amountpayment" => json => $put_data2); |
219 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
220 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
221 |
$t->request_ok($tx) |
222 |
->status_is(404); |
223 |
|
224 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$borrowernumber3/amountpayment" => json => {amount => 0}); |
225 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
226 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
227 |
$t->request_ok($tx) |
228 |
->status_is(400); |
229 |
|
230 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$borrowernumber3/amountpayment" => json => {amount => 'foo'}); |
231 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
232 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
233 |
$t->request_ok($tx) |
234 |
->status_is(400); |
235 |
|
236 |
$tx = $t->ua->build_tx(PUT => "/api/v1/accountlines/$borrowernumber3/amountpayment" => json => $put_data2); |
237 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
238 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
239 |
$t->request_ok($tx) |
240 |
->status_is(200); |
241 |
|
242 |
$accountline_partiallypayed = Koha::Accountlines->search({'borrowernumber' => $borrowernumber3, 'amount' => 26})->unblessed()->[0]; |
243 |
|
244 |
is($accountline_partiallypayed->{amountoutstanding}, '2.000000'); |
141 |
|
245 |
|
142 |
$dbh->rollback; |
246 |
$dbh->rollback; |
143 |
- |
|
|