From 26fb0e35c0f5b92dc7bc582f70e29c51155f9de2 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Thu, 4 May 2023 14:09:10 +0000 Subject: [PATCH] Bug 29453: (follow-up) Add tests and fix minimum amount in credit.yaml definition Signed-off-by: Kyle M Hall --- api/v1/swagger/definitions/credit.yaml | 1 - t/db_dependent/api/v1/patrons_accounts.t | 79 +++++++++++++++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/api/v1/swagger/definitions/credit.yaml b/api/v1/swagger/definitions/credit.yaml index df76473308..6e997d5f12 100644 --- a/api/v1/swagger/definitions/credit.yaml +++ b/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 diff --git a/t/db_dependent/api/v1/patrons_accounts.t b/t/db_dependent/api/v1/patrons_accounts.t index cada141ef3..3118171b7a 100755 --- a/t/db_dependent/api/v1/patrons_accounts.t +++ b/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; +}; -- 2.30.2