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

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 898cd3b82e)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Joonas Kylmälä 2020-08-21 16:21:42 +03:00 committed by Lucas Gass
parent 7a8b7ba2f4
commit 00570ae969
1 changed files with 35 additions and 1 deletions

View File

@ -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;
};