Bugzilla – Attachment 154516 Details for
Bug 34277
Add an API endpoint to return all patrons with outstanding charges
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34277: Add unit test
Bug-34277-Add-unit-test.patch (text/plain), 7.76 KB, created by
Matt Blenkinsop
on 2023-08-17 10:22:16 UTC
(
hide
)
Description:
Bug 34277: Add unit test
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-08-17 10:22:16 UTC
Size:
7.76 KB
patch
obsolete
>From 4275a44be51b4a4fd7881dda7b974a5f53ede823 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Fri, 14 Jul 2023 12:52:43 +0000 >Subject: [PATCH] Bug 34277: Add unit test > >prove t/db_dependent/api/v1/patrons_accounts.t >--- > t/db_dependent/api/v1/patrons_accounts.t | 175 ++++++++++++++++++++++- > 1 file changed, 174 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/patrons_accounts.t b/t/db_dependent/api/v1/patrons_accounts.t >index 6217a0fad2..a5008040c8 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 => 5; >+use Test::More tests => 6; > > use Test::Mojo; > >@@ -59,6 +59,7 @@ subtest 'get_balance() tests' => sub { > $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") > ->status_is(200)->json_is( > { >+ borrowernumber => $patron->borrowernumber, > balance => 0.00, > outstanding_debits => { total => 0, lines => [] }, > outstanding_credits => { total => 0, lines => [] } >@@ -92,6 +93,7 @@ subtest 'get_balance() tests' => sub { > $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") > ->status_is(200)->json_is( > { >+ borrowernumber => $patron->borrowernumber, > balance => 100.01, > outstanding_debits => { > total => 100.01, >@@ -117,6 +119,7 @@ subtest 'get_balance() tests' => sub { > $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") > ->status_is(200)->json_is( > { >+ borrowernumber => $patron->borrowernumber, > balance => 0, > outstanding_debits => { total => 0, lines => [] }, > outstanding_credits => { total => 0, lines => [] } >@@ -139,6 +142,7 @@ subtest 'get_balance() tests' => sub { > $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") > ->status_is(200)->json_is( > { >+ borrowernumber => $patron->borrowernumber, > balance => -10, > outstanding_debits => { > total => 0, >@@ -167,6 +171,7 @@ subtest 'get_balance() tests' => sub { > $t->get_ok("//$userid:$password@/api/v1/patrons/$patron_id/account") > ->status_is(200)->json_is( > { >+ borrowernumber => $patron->borrowernumber, > balance => 40.00, > outstanding_debits => { > total => 50.00, >@@ -367,6 +372,9 @@ subtest 'list_debits() test' => sub { > ->tx->res->json; > > is(140, $ret->[0]->{amount} + $ret->[1]->{amount}, 'Total debits are 140'); >+ >+ $schema->storage->txn_rollback; >+ > }; > > subtest 'add_debit() tests' => sub { >@@ -472,3 +480,168 @@ subtest 'add_debit() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'get_patron_balances() tests' => sub { >+ plan tests => 15; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::Account::Lines->search->delete; >+ >+ 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_2 = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 1 } >+ } >+ ); >+ $patron_2->set_password( { password => $password, skip_validation => 1 } ); >+ >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $account = $patron->account; >+ my $account_2 = $patron_2->account; >+ >+ $t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") >+ ->status_is(200)->json_is([]); >+ >+ my $debit_1 = $account->add_debit( >+ { >+ amount => 10.00, >+ description => "A description", >+ type => "NEW_CARD", >+ user_id => $patron->borrowernumber, >+ library_id => $library->id, >+ interface => 'test', >+ } >+ )->store(); >+ $debit_1->discard_changes; >+ >+ $t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") >+ ->status_is(200)->json_is([ >+ { >+ borrowernumber => $patron->borrowernumber, >+ balance => 10.00, >+ outstanding_debits => { >+ total => 10.00, >+ lines => [ $debit_1->to_api ] >+ }, >+ outstanding_credits => { >+ total => 0, >+ lines => [] >+ } >+ } >+ ]); >+ my $debit_2 = $account_2->add_debit( >+ { >+ amount => 5.00, >+ description => "A description", >+ type => "NEW_CARD", >+ user_id => $patron_2->borrowernumber, >+ library_id => $library->id, >+ interface => 'test', >+ } >+ )->store(); >+ $debit_2->discard_changes; >+ >+ $t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") >+ ->status_is(200)->json_is([ >+ { >+ borrowernumber => $patron->borrowernumber, >+ balance => 10.00, >+ outstanding_debits => { >+ total => 10.00, >+ lines => [ $debit_1->to_api ] >+ }, >+ outstanding_credits => { >+ total => 0, >+ lines => [] >+ } >+ }, >+ { >+ borrowernumber => $patron_2->borrowernumber, >+ balance => 5.00, >+ outstanding_debits => { >+ total => 5.00, >+ lines => [ $debit_2->to_api ] >+ }, >+ outstanding_credits => { >+ total => 0, >+ lines => [] >+ } >+ } >+ ]); >+ >+ my $credit_1 = $account->add_credit( >+ { >+ amount => 10, >+ user_id => $patron->id, >+ library_id => $library->id, >+ interface => 'test' >+ } >+ ); >+ $credit_1->discard_changes; >+ >+ $t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") >+ ->status_is(200)->json_is([ >+ { >+ borrowernumber => $patron->borrowernumber, >+ balance => 0, >+ outstanding_debits => { >+ total => 10.00, >+ lines => [ $debit_1->to_api ] >+ }, >+ outstanding_credits => { >+ total => -10.00, >+ lines => [ $credit_1->to_api ] >+ } >+ }, >+ { >+ borrowernumber => $patron_2->borrowernumber, >+ balance => 5.00, >+ outstanding_debits => { >+ total => 5.00, >+ lines => [ $debit_2->to_api ] >+ }, >+ outstanding_credits => { >+ total => 0, >+ lines => [] >+ } >+ } >+ ]); >+ >+ $account_2->pay( >+ { >+ amount => 5.00, >+ note => 'Fine paid in full', >+ description => 'Closed', >+ library_id => $patron_2->branchcode, >+ account_type => 'PAYMENT' >+ } >+ ); >+ >+ $t->get_ok("//$userid:$password@/api/v1/patrons/get_balances") >+ ->status_is(200)->json_is([ >+ { >+ borrowernumber => $patron->borrowernumber, >+ balance => 0, >+ outstanding_debits => { >+ total => 10.00, >+ lines => [ $debit_1->to_api ] >+ }, >+ outstanding_credits => { >+ total => -10.00, >+ lines => [ $credit_1->to_api ] >+ } >+ } >+ ]); >+ >+ $schema->storage->txn_rollback; >+} >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34277
:
153477
|
153478
| 154516 |
156185
|
156186
|
156187