|
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 |
my $patron = $builder->build_object( |
| 490 |
{ |
| 491 |
class => 'Koha::Patrons', |
| 492 |
value => { flags => 1 } |
| 493 |
} |
| 494 |
); |
| 495 |
my $password = 'thePassword123'; |
| 496 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 497 |
my $userid = $patron->userid; |
| 498 |
my $patron_2 = $builder->build_object( |
| 499 |
{ |
| 500 |
class => 'Koha::Patrons', |
| 501 |
value => { flags => 1 } |
| 502 |
} |
| 503 |
); |
| 504 |
$patron_2->set_password( { password => $password, skip_validation => 1 } ); |
| 505 |
|
| 506 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 507 |
my $account = $patron->account; |
| 508 |
my $account_2 = $patron_2->account; |
| 509 |
|
| 510 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
| 511 |
->status_is(200)->json_is([]); |
| 512 |
|
| 513 |
my $debit_1 = $account->add_debit( |
| 514 |
{ |
| 515 |
amount => 10.00, |
| 516 |
description => "A description", |
| 517 |
type => "NEW_CARD", |
| 518 |
user_id => $patron->borrowernumber, |
| 519 |
library_id => $library->id, |
| 520 |
interface => 'test', |
| 521 |
} |
| 522 |
)->store(); |
| 523 |
$debit_1->discard_changes; |
| 524 |
|
| 525 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
| 526 |
->status_is(200)->json_is([ |
| 527 |
{ |
| 528 |
borrowernumber => $patron->borrowernumber, |
| 529 |
balance => 10.00, |
| 530 |
outstanding_debits => { |
| 531 |
total => 10.00, |
| 532 |
lines => [ $debit_1->to_api ] |
| 533 |
}, |
| 534 |
outstanding_credits => { |
| 535 |
total => 0, |
| 536 |
lines => [] |
| 537 |
} |
| 538 |
} |
| 539 |
]); |
| 540 |
my $debit_2 = $account_2->add_debit( |
| 541 |
{ |
| 542 |
amount => 5.00, |
| 543 |
description => "A description", |
| 544 |
type => "NEW_CARD", |
| 545 |
user_id => $patron_2->borrowernumber, |
| 546 |
library_id => $library->id, |
| 547 |
interface => 'test', |
| 548 |
} |
| 549 |
)->store(); |
| 550 |
$debit_2->discard_changes; |
| 551 |
|
| 552 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
| 553 |
->status_is(200)->json_is([ |
| 554 |
{ |
| 555 |
borrowernumber => $patron->borrowernumber, |
| 556 |
balance => 10.00, |
| 557 |
outstanding_debits => { |
| 558 |
total => 10.00, |
| 559 |
lines => [ $debit_1->to_api ] |
| 560 |
}, |
| 561 |
outstanding_credits => { |
| 562 |
total => 0, |
| 563 |
lines => [] |
| 564 |
} |
| 565 |
}, |
| 566 |
{ |
| 567 |
borrowernumber => $patron_2->borrowernumber, |
| 568 |
balance => 5.00, |
| 569 |
outstanding_debits => { |
| 570 |
total => 5.00, |
| 571 |
lines => [ $debit_2->to_api ] |
| 572 |
}, |
| 573 |
outstanding_credits => { |
| 574 |
total => 0, |
| 575 |
lines => [] |
| 576 |
} |
| 577 |
} |
| 578 |
]); |
| 579 |
|
| 580 |
my $credit_1 = $account->add_credit( |
| 581 |
{ |
| 582 |
amount => 10, |
| 583 |
user_id => $patron->id, |
| 584 |
library_id => $library->id, |
| 585 |
interface => 'test' |
| 586 |
} |
| 587 |
); |
| 588 |
$credit_1->discard_changes; |
| 589 |
|
| 590 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
| 591 |
->status_is(200)->json_is([ |
| 592 |
{ |
| 593 |
borrowernumber => $patron->borrowernumber, |
| 594 |
balance => 0, |
| 595 |
outstanding_debits => { |
| 596 |
total => 10.00, |
| 597 |
lines => [ $debit_1->to_api ] |
| 598 |
}, |
| 599 |
outstanding_credits => { |
| 600 |
total => -10.00, |
| 601 |
lines => [ $credit_1->to_api ] |
| 602 |
} |
| 603 |
}, |
| 604 |
{ |
| 605 |
borrowernumber => $patron_2->borrowernumber, |
| 606 |
balance => 5.00, |
| 607 |
outstanding_debits => { |
| 608 |
total => 5.00, |
| 609 |
lines => [ $debit_2->to_api ] |
| 610 |
}, |
| 611 |
outstanding_credits => { |
| 612 |
total => 0, |
| 613 |
lines => [] |
| 614 |
} |
| 615 |
} |
| 616 |
]); |
| 617 |
|
| 618 |
$account_2->pay( |
| 619 |
{ |
| 620 |
amount => 5.00, |
| 621 |
note => 'Fine paid in full', |
| 622 |
description => 'Closed', |
| 623 |
library_id => $patron_2->branchcode, |
| 624 |
account_type => 'PAYMENT' |
| 625 |
} |
| 626 |
); |
| 627 |
|
| 628 |
$t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") |
| 629 |
->status_is(200)->json_is([ |
| 630 |
{ |
| 631 |
borrowernumber => $patron->borrowernumber, |
| 632 |
balance => 0, |
| 633 |
outstanding_debits => { |
| 634 |
total => 10.00, |
| 635 |
lines => [ $debit_1->to_api ] |
| 636 |
}, |
| 637 |
outstanding_credits => { |
| 638 |
total => -10.00, |
| 639 |
lines => [ $credit_1->to_api ] |
| 640 |
} |
| 641 |
} |
| 642 |
]); |
| 643 |
|
| 644 |
$schema->storage->txn_rollback; |
| 645 |
} |