Bug 22610: (QA follow-up) Add unit tests for FeePayment

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2019-07-19 12:27:33 +01:00
parent 12db9990b5
commit 3326ce607d
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -4,7 +4,7 @@
# Current state is very rudimentary. Please help to extend it! # Current state is very rudimentary. Please help to extend it!
use Modern::Perl; use Modern::Perl;
use Test::More tests => 4; use Test::More tests => 5;
use Koha::Database; use Koha::Database;
use t::lib::TestBuilder; use t::lib::TestBuilder;
@ -12,6 +12,7 @@ use t::lib::Mocks;
use C4::SIP::ILS::Patron; use C4::SIP::ILS::Patron;
use C4::SIP::ILS::Transaction::RenewAll; use C4::SIP::ILS::Transaction::RenewAll;
use C4::SIP::ILS::Transaction::Checkout; use C4::SIP::ILS::Transaction::Checkout;
use C4::SIP::ILS::Transaction::FeePayment;
use C4::Reserves; use C4::Reserves;
use Koha::IssuingRules; use Koha::IssuingRules;
@ -95,4 +96,44 @@ subtest fill_holds_at_checkout => sub {
$transaction = C4::SIP::ILS::Transaction::Checkout->new(); $transaction = C4::SIP::ILS::Transaction::Checkout->new();
is( $sip_item->{barcode}, $item1->{barcode}, "Item assigned to transaction" ); is( $sip_item->{barcode}, $item1->{barcode}, "Item assigned to transaction" );
}; };
subtest "FeePayment->pay tests" => sub {
plan tests => 5;
# Create a borrower and add some outstanding debts to their account
my $patron = $builder->build( { source => 'Borrower' } );
my $account =
Koha::Account->new( { patron_id => $patron->{borrowernumber} } );
my $debt1 = $account->add_debit(
{ type => 'account', amount => 100, interface => 'commandline' } );
my $debt2 = $account->add_debit(
{ type => 'account', amount => 200, interface => 'commandline' } );
# Instantiate a new FeePayment transaction object
my $trans = C4::SIP::ILS::Transaction::FeePayment->new();
is(
ref $trans,
"C4::SIP::ILS::Transaction::FeePayment",
"New fee transaction created"
);
# Test the 'pay' method
# FIXME: pay should not require a borrowernumber
# (we should reach out to the transaction which should contain a patron object)
my $pay_type = '00'; # 00 - Cash, 01 - VISA, 02 - Creditcard
my $ok =
$trans->pay( $patron->{borrowernumber}, 100, $pay_type, $debt1->id, 0,
0 );
ok( $ok, "FeePayment transaction succeeded" );
$debt1->discard_changes;
is( $debt1->amountoutstanding + 0, 0,
"Debt1 was reduced to 0 as expected" );
my $offsets = Koha::Account::Offsets->search(
{ debit_id => $debt1->id, credit_id => { '!=' => undef } } );
is( $offsets->count, 1, "FeePayment produced an offset line correctly" );
my $credit = $offsets->next->credit;
is( $credit->payment_type, 'SIP00', "Payment type was set correctly" );
};
$schema->storage->txn_rollback; $schema->storage->txn_rollback;