Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 5; |
20 |
use Test::More tests => 6; |
21 |
|
21 |
|
22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
23 |
|
23 |
|
Lines 59-64
subtest 'get_balance() tests' => sub {
Link Here
|
59 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
59 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
60 |
->status_is(200)->json_is( |
60 |
->status_is(200)->json_is( |
61 |
{ |
61 |
{ |
|
|
62 |
borrowernumber => $patron->borrowernumber, |
62 |
balance => 0.00, |
63 |
balance => 0.00, |
63 |
outstanding_debits => { total => 0, lines => [] }, |
64 |
outstanding_debits => { total => 0, lines => [] }, |
64 |
outstanding_credits => { total => 0, lines => [] } |
65 |
outstanding_credits => { total => 0, lines => [] } |
Lines 92-97
subtest 'get_balance() tests' => sub {
Link Here
|
92 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
93 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
93 |
->status_is(200)->json_is( |
94 |
->status_is(200)->json_is( |
94 |
{ |
95 |
{ |
|
|
96 |
borrowernumber => $patron->borrowernumber, |
95 |
balance => 100.01, |
97 |
balance => 100.01, |
96 |
outstanding_debits => { |
98 |
outstanding_debits => { |
97 |
total => 100.01, |
99 |
total => 100.01, |
Lines 117-122
subtest 'get_balance() tests' => sub {
Link Here
|
117 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
119 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
118 |
->status_is(200)->json_is( |
120 |
->status_is(200)->json_is( |
119 |
{ |
121 |
{ |
|
|
122 |
borrowernumber => $patron->borrowernumber, |
120 |
balance => 0, |
123 |
balance => 0, |
121 |
outstanding_debits => { total => 0, lines => [] }, |
124 |
outstanding_debits => { total => 0, lines => [] }, |
122 |
outstanding_credits => { total => 0, lines => [] } |
125 |
outstanding_credits => { total => 0, lines => [] } |
Lines 139-144
subtest 'get_balance() tests' => sub {
Link Here
|
139 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
142 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
140 |
->status_is(200)->json_is( |
143 |
->status_is(200)->json_is( |
141 |
{ |
144 |
{ |
|
|
145 |
borrowernumber => $patron->borrowernumber, |
142 |
balance => -10, |
146 |
balance => -10, |
143 |
outstanding_debits => { |
147 |
outstanding_debits => { |
144 |
total => 0, |
148 |
total => 0, |
Lines 167-172
subtest 'get_balance() tests' => sub {
Link Here
|
167 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
171 |
$t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") |
168 |
->status_is(200)->json_is( |
172 |
->status_is(200)->json_is( |
169 |
{ |
173 |
{ |
|
|
174 |
borrowernumber => $patron->borrowernumber, |
170 |
balance => 40.00, |
175 |
balance => 40.00, |
171 |
outstanding_debits => { |
176 |
outstanding_debits => { |
172 |
total => 50.00, |
177 |
total => 50.00, |
Lines 367-372
subtest 'list_debits() test' => sub {
Link Here
|
367 |
->tx->res->json; |
372 |
->tx->res->json; |
368 |
|
373 |
|
369 |
is(140, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total debits are 140'); |
374 |
is(140, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total debits are 140'); |
|
|
375 |
|
376 |
$schema->storage->txn_rollback; |
377 |
|
370 |
}; |
378 |
}; |
371 |
|
379 |
|
372 |
subtest 'add_debit() tests' => sub { |
380 |
subtest 'add_debit() tests' => sub { |
Lines 472-474
subtest 'add_debit() tests' => sub {
Link Here
|
472 |
|
480 |
|
473 |
$schema->storage->txn_rollback; |
481 |
$schema->storage->txn_rollback; |
474 |
}; |
482 |
}; |
475 |
- |
483 |
|
|
|
484 |
subtest 'get_patron_balances() tests' => sub { |
485 |
plan tests => 15; |
486 |
|
487 |
$schema->storage->txn_begin; |
488 |
|
489 |
Koha::Account::Lines->search->delete; |
490 |
|
491 |
my $patron = $builder->build_object( |
492 |
{ |
493 |
class => 'Koha::Patrons', |
494 |
value => { flags => 1 } |
495 |
} |
496 |
); |
497 |
my $password = 'thePassword123'; |
498 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
499 |
my $userid = $patron->userid; |
500 |
my $patron_2 = $builder->build_object( |
501 |
{ |
502 |
class => 'Koha::Patrons', |
503 |
value => { flags => 1 } |
504 |
} |
505 |
); |
506 |
$patron_2->set_password( { password => $password, skip_validation => 1 } ); |
507 |
|
508 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
509 |
my $account = $patron->account; |
510 |
my $account_2 = $patron_2->account; |
511 |
|
512 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
513 |
->status_is(200)->json_is([]); |
514 |
|
515 |
my $debit_1 = $account->add_debit( |
516 |
{ |
517 |
amount => 10.00, |
518 |
description => "A description", |
519 |
type => "NEW_CARD", |
520 |
user_id => $patron->borrowernumber, |
521 |
library_id => $library->id, |
522 |
interface => 'test', |
523 |
} |
524 |
)->store(); |
525 |
$debit_1->discard_changes; |
526 |
|
527 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
528 |
->status_is(200)->json_is([ |
529 |
{ |
530 |
borrowernumber => $patron->borrowernumber, |
531 |
balance => 10.00, |
532 |
outstanding_debits => { |
533 |
total => 10.00, |
534 |
lines => [ $debit_1->to_api ] |
535 |
}, |
536 |
outstanding_credits => { |
537 |
total => 0, |
538 |
lines => [] |
539 |
} |
540 |
} |
541 |
]); |
542 |
my $debit_2 = $account_2->add_debit( |
543 |
{ |
544 |
amount => 5.00, |
545 |
description => "A description", |
546 |
type => "NEW_CARD", |
547 |
user_id => $patron_2->borrowernumber, |
548 |
library_id => $library->id, |
549 |
interface => 'test', |
550 |
} |
551 |
)->store(); |
552 |
$debit_2->discard_changes; |
553 |
|
554 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
555 |
->status_is(200)->json_is([ |
556 |
{ |
557 |
borrowernumber => $patron->borrowernumber, |
558 |
balance => 10.00, |
559 |
outstanding_debits => { |
560 |
total => 10.00, |
561 |
lines => [ $debit_1->to_api ] |
562 |
}, |
563 |
outstanding_credits => { |
564 |
total => 0, |
565 |
lines => [] |
566 |
} |
567 |
}, |
568 |
{ |
569 |
borrowernumber => $patron_2->borrowernumber, |
570 |
balance => 5.00, |
571 |
outstanding_debits => { |
572 |
total => 5.00, |
573 |
lines => [ $debit_2->to_api ] |
574 |
}, |
575 |
outstanding_credits => { |
576 |
total => 0, |
577 |
lines => [] |
578 |
} |
579 |
} |
580 |
]); |
581 |
|
582 |
my $credit_1 = $account->add_credit( |
583 |
{ |
584 |
amount => 10, |
585 |
user_id => $patron->id, |
586 |
library_id => $library->id, |
587 |
interface => 'test' |
588 |
} |
589 |
); |
590 |
$credit_1->discard_changes; |
591 |
|
592 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
593 |
->status_is(200)->json_is([ |
594 |
{ |
595 |
borrowernumber => $patron->borrowernumber, |
596 |
balance => 0, |
597 |
outstanding_debits => { |
598 |
total => 10.00, |
599 |
lines => [ $debit_1->to_api ] |
600 |
}, |
601 |
outstanding_credits => { |
602 |
total => -10.00, |
603 |
lines => [ $credit_1->to_api ] |
604 |
} |
605 |
}, |
606 |
{ |
607 |
borrowernumber => $patron_2->borrowernumber, |
608 |
balance => 5.00, |
609 |
outstanding_debits => { |
610 |
total => 5.00, |
611 |
lines => [ $debit_2->to_api ] |
612 |
}, |
613 |
outstanding_credits => { |
614 |
total => 0, |
615 |
lines => [] |
616 |
} |
617 |
} |
618 |
]); |
619 |
|
620 |
$account_2->pay( |
621 |
{ |
622 |
amount => 5.00, |
623 |
note => 'Fine paid in full', |
624 |
description => 'Closed', |
625 |
library_id => $patron_2->branchcode, |
626 |
account_type => 'PAYMENT' |
627 |
} |
628 |
); |
629 |
|
630 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
631 |
->status_is(200)->json_is([ |
632 |
{ |
633 |
borrowernumber => $patron->borrowernumber, |
634 |
balance => 0, |
635 |
outstanding_debits => { |
636 |
total => 10.00, |
637 |
lines => [ $debit_1->to_api ] |
638 |
}, |
639 |
outstanding_credits => { |
640 |
total => -10.00, |
641 |
lines => [ $credit_1->to_api ] |
642 |
} |
643 |
} |
644 |
]); |
645 |
|
646 |
$schema->storage->txn_rollback; |
647 |
} |