Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 3; |
21 |
|
21 |
|
22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
23 |
|
23 |
|
Lines 268-270
subtest 'add_credit() tests' => sub {
Link Here
|
268 |
|
268 |
|
269 |
$schema->storage->txn_rollback; |
269 |
$schema->storage->txn_rollback; |
270 |
}; |
270 |
}; |
271 |
- |
271 |
|
|
|
272 |
subtest 'add_debit() tests' => sub { |
273 |
|
274 |
plan tests => 13; |
275 |
|
276 |
$schema->storage->txn_begin; |
277 |
|
278 |
my $patron = $builder->build_object({ |
279 |
class => 'Koha::Patrons', |
280 |
value => { flags => 1 } |
281 |
}); |
282 |
my $password = 'thePassword123'; |
283 |
$patron->set_password({ password => $password, skip_validation => 1 }); |
284 |
my $userid = $patron->userid; |
285 |
|
286 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
287 |
my $patron_id = $patron->id; |
288 |
my $account = $patron->account; |
289 |
|
290 |
is( $account->outstanding_debits->count, 0, 'No outstanding debits for patron' ); |
291 |
is( $account->outstanding_credits->count, 0, 'No outstanding credits for patron' ); |
292 |
|
293 |
my $debit = { |
294 |
amount => 100, |
295 |
description => "A description", |
296 |
debit_type => "NEW_CARD", |
297 |
user_id => $patron->borrowernumber, |
298 |
interface => 'test', |
299 |
library_id => $library->id, |
300 |
}; |
301 |
|
302 |
my $ret = $t->post_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => json => $debit) |
303 |
->status_is(201)->tx->res->json; |
304 |
my $account_line = Koha::Account::Lines->find( $ret->{account_line_id} ); |
305 |
|
306 |
is_deeply( $ret, $account_line->to_api, 'Line returned correctly' ); |
307 |
|
308 |
is( $account_line->branchcode, |
309 |
$library->id, 'Library id is sored correctly' ); |
310 |
|
311 |
my $outstanding_debits = $account->outstanding_debits; |
312 |
is( $outstanding_debits->count, 1 ); |
313 |
is( $outstanding_debits->total_outstanding, 100 ); |
314 |
|
315 |
my $credit_1 = $account->add_credit( |
316 |
{ |
317 |
amount => 10, |
318 |
interface => 'test', |
319 |
} |
320 |
)->store()->apply({ debits => [ $account_line ] }); |
321 |
my $credit_2 = $account->add_credit( |
322 |
{ |
323 |
amount => 15, |
324 |
interface => 'test' |
325 |
} |
326 |
)->store()->apply({ debits => [ $account_line ]}); |
327 |
|
328 |
is( $account->outstanding_credits->total_outstanding, 0 ); |
329 |
is( $account->outstanding_debits->total_outstanding, |
330 |
75, "Credits partially cancelled debit" ); |
331 |
|
332 |
my $account_line_id = $ret->{account_line_id}; |
333 |
|
334 |
$t->post_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => json => $debit) |
335 |
->status_is(201); |
336 |
|
337 |
is( $account->outstanding_debits->total_outstanding, |
338 |
175, "Debit added to total outstanding debits" ); |
339 |
|
340 |
$schema->storage->txn_rollback; |
341 |
}; |