Koha/t/db_dependent/Koha/Account/Lines.t
Martin Renvoize 8d64d08c41 Bug 19036: (follow-up) Test credits should be credits
A series of accountlines added to mock credits were being added with a
debit_type_code instead of a valid credit_type_code and so were being
mis-identified by the new credit numbering code trigger in the store
routine.

This patch updates the test to correctly identify the credits as credits

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2020-08-21 12:32:43 +02:00

330 lines
11 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2018 Koha Development team
#
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>
use Modern::Perl;
use Test::More tests => 4;
use Test::Exception;
use Test::MockModule;
use DateTime;
use Koha::Account;
use Koha::Account::Lines;
use Koha::Account::Offsets;
use t::lib::Mocks;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
subtest 'total_outstanding() tests' => sub {
plan tests => 5;
$schema->storage->txn_begin;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total_outstanding, 0, 'total_outstanding returns 0 if no lines (undef case)' );
my $debit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
amountoutstanding => 10,
interface => 'commandline',
}
)->store;
my $debit_2 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
amountoutstanding => 10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total_outstanding, 20, 'total_outstanding sums correctly' );
my $credit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -10,
amountoutstanding => -10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total_outstanding, 10, 'total_outstanding sums correctly' );
my $credit_2 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -10,
amountoutstanding => -10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total_outstanding, 0, 'total_outstanding sums correctly' );
my $credit_3 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -100,
amountoutstanding => -100,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total_outstanding, -100, 'total_outstanding sums correctly' );
$schema->storage->txn_rollback;
};
subtest 'total() tests' => sub {
plan tests => 5;
$schema->storage->txn_begin;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total, 0, 'total returns 0 if no lines (undef case)' );
my $debit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
amountoutstanding => 10,
interface => 'commandline',
}
)->store;
my $debit_2 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
amountoutstanding => 10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total, 20, 'total sums correctly' );
my $credit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -10,
amountoutstanding => -10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total, 10, 'total sums correctly' );
my $credit_2 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -10,
amountoutstanding => -10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total, 0, 'total sums correctly' );
my $credit_3 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -100,
amountoutstanding => -100,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->total, -100, 'total sums correctly' );
$schema->storage->txn_rollback;
};
subtest 'credits_total() tests' => sub {
plan tests => 5;
$schema->storage->txn_begin;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->credits_total, 0, 'credits_total returns 0 if no lines (undef case)' );
my $debit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
amountoutstanding => 10,
interface => 'commandline',
}
)->store;
my $debit_2 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
amountoutstanding => 10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->credits_total, 0, 'credits_total sums correctly' );
my $credit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -10,
amountoutstanding => -10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->credits_total, -10, 'credits_total sums correctly' );
my $credit_2 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -10,
amountoutstanding => -10,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->credits_total, -20, 'credits_total sums correctly' );
my $credit_3 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -100,
amountoutstanding => -100,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->credits_total, -120, 'credits_total sums correctly' );
$schema->storage->txn_rollback;
};
subtest 'debits_total() tests' => sub {
plan tests => 5;
$schema->storage->txn_begin;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->debits_total, 0, 'debits_total returns 0 if no lines (undef case)' );
my $debit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
amountoutstanding => 0,
interface => 'commandline',
}
)->store;
my $debit_2 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
debit_type_code => "OVERDUE",
status => "RETURNED",
amount => 10,
amountoutstanding => 0,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->debits_total, 20, 'debits_total sums correctly' );
my $credit_1 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -10,
amountoutstanding => 0,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->debits_total, 20, 'debits_total sums correctly' );
my $credit_2 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -10,
amountoutstanding => 0,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->debits_total, 20, 'debits_total sums correctly' );
my $credit_3 = Koha::Account::Line->new(
{ borrowernumber => $patron->id,
credit_type_code => "PAYMENT",
amount => -100,
amountoutstanding => 0,
interface => 'commandline',
}
)->store;
$lines = Koha::Account::Lines->search({ borrowernumber => $patron->id });
is( $lines->debits_total, 20, 'debits_total sums correctly' );
$schema->storage->txn_rollback;
};
1;