@@ -, +, @@ credit.yaml definition --- api/v1/swagger/definitions/credit.yaml | 1 - t/db_dependent/api/v1/patrons_accounts.t | 79 +++++++++++++++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) --- a/api/v1/swagger/definitions/credit.yaml +++ a/api/v1/swagger/definitions/credit.yaml @@ -9,7 +9,6 @@ properties: description: Internal account line identifier amount: type: number - minimum: 0 description: Credit amount amount_outstanding: type: number --- a/t/db_dependent/api/v1/patrons_accounts.t +++ a/t/db_dependent/api/v1/patrons_accounts.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 4; use Test::Mojo; @@ -268,3 +268,80 @@ subtest 'add_credit() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'list_credits() test' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object({ + class => 'Koha::Patrons', + value => { flags => 1 } + }); + my $password = 'thePassword123'; + $patron->set_password({ password => $password, skip_validation => 1 }); + my $userid = $patron->userid; + my $patron_id = $patron->borrowernumber; + my $account = $patron->account; + + $account->add_credit({ + type => 'PAYMENT', + amount => 35, + interface => 'staff', + }); + $account->add_credit({ + type => 'PAYMENT', + amount => 70, + interface => 'staff', + }); + + my $ret = $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/credits") + ->status_is(200) + ->tx->res->json; + + is(-105, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total credits are -105'); + + $schema->storage->txn_rollback; +}; + + +subtest 'list_debits() test' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object({ + class => 'Koha::Patrons', + value => { flags => 1 } + }); + my $password = 'thePassword123'; + $patron->set_password({ password => $password, skip_validation => 1 }); + my $userid = $patron->userid; + my $patron_id = $patron->borrowernumber; + my $account = $patron->account; + + $account->add_debit( + { amount => 100, + description => "A description", + type => "NEW_CARD", + user_id => $patron->borrowernumber, + interface => 'test', + } + ); + $account->add_debit( + { amount => 40, + description => "A description", + type => "NEW_CARD", + user_id => $patron->borrowernumber, + interface => 'test', + } + ); + + my $ret = $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account/debits") + ->status_is(200) + ->tx->res->json; + + is(140, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total debits are 140'); + + $schema->storage->txn_rollback; +}; --