From 84a48f921586e8950f3655b37c6dcfa2368fc251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Fri, 21 Aug 2020 16:21:42 +0300 Subject: [PATCH] Bug 26271: Add failing test to reveal issue with patrons API endpoint When manager_id is null/undef the API returns error code 500. To test: 1) Notice failure when running prove t/db_dependent/api/v1/patrons_accounts.t --- t/db_dependent/api/v1/patrons_accounts.t | 36 +++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/patrons_accounts.t b/t/db_dependent/api/v1/patrons_accounts.t index 5373f54c18..fd8bb39589 100644 --- a/t/db_dependent/api/v1/patrons_accounts.t +++ b/t/db_dependent/api/v1/patrons_accounts.t @@ -40,7 +40,7 @@ my $t = Test::Mojo->new('Koha::REST::V1'); subtest 'get_balance() tests' => sub { - plan tests => 12; + plan tests => 15; $schema->storage->txn_begin; @@ -149,6 +149,40 @@ subtest 'get_balance() tests' => sub { } ); + # Accountline without manager_id (happens with fines.pl cron for example) + my $account_line_3 = Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + date => \'NOW()', + amount => 50, + description => "A description", + debit_type_code => "NEW_CARD", # New card + amountoutstanding => 50, + manager_id => undef, + branchcode => $library->id, + interface => 'test', + } + )->store(); + $account_line_3->discard_changes; + + $tx = $t->ua->build_tx( GET => "/api/v1/patrons/$patron_id/account" ); + $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); + $tx->req->env( { REMOTE_ADDR => '127.0.0.1' } ); + $t->request_ok($tx)->status_is(200)->json_is( + { balance => 40.00, + outstanding_debits => { + total => 50.00, + lines => [ + $account_line_3->to_api + ] + }, + outstanding_credits => { + total => -10, + lines => [ $credit_line->to_api ] + } + } + ); + $schema->storage->txn_rollback; }; -- 2.11.0