From aa62f42d2345c711adccb51ab95b9b0b3a8d5114 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 16 Apr 2021 08:06:17 -0400 Subject: [PATCH] Bug 27916: Add unit tests --- t/db_dependent/SIP/Message.t | 60 +++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t index e032b7964e..c7450d7217 100755 --- a/t/db_dependent/SIP/Message.t +++ b/t/db_dependent/SIP/Message.t @@ -21,7 +21,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use Test::MockObject; use Test::MockModule; use Test::Warn; @@ -31,6 +31,7 @@ use t::lib::TestBuilder; use C4::Reserves qw(AddReserve); use C4::Circulation qw( AddReturn ); +use Koha::Account::Lines; use Koha::Database; use Koha::AuthUtils qw(hash_password); use Koha::DateUtils; @@ -337,6 +338,63 @@ subtest 'Patron info summary > 5 should not crash server' => sub { $schema->storage->txn_rollback; }; +subtest 'Fee paid message can crash SIP server if paying fee that is not "renewable"' => sub { + + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + plan tests => 6; + my $builder = t::lib::TestBuilder->new(); + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my ( $response, $findpatron ); + my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); + my $borrower = $builder->build({ + source => 'Borrower', + value => { + lastseen => '2001-01-01', + password => hash_password( PATRON_PW ), + branchcode => $branchcode, + }, + }); + my $cardnum = $borrower->{cardnumber}; + my $sip_patron = C4::SIP::ILS::Patron->new( $cardnum ); + $findpatron = $sip_patron; + + my $line = Koha::Account::Line->new( + { + borrowernumber => $borrower->{borrowernumber}, + manager_id => $borrower->{borrowernumber}, + itemnumber => 1, + debit_type_code => "OVERDUE", + status => "RETURNED", + amount => 5, + interface => 'commandline', + } + )->store; + + my $fee_type = '01'; + my $pay_type = '00'; + my $currency_type = 'USD'; + my $fee_amount = '5.00'; + + my $siprequest = FEE_PAID . 'YYYYMMDDZZZZHHMMSS'. + $fee_type . $pay_type . $currency_type . + FID_FEE_AMT . $fee_amount . '|' . + FID_FEE_ID . $line->id . '|' . + FID_INST_ID . $branchcode . '|' . + FID_PATRON_ID . $cardnum . '|' . + FID_PATRON_PWD . PATRON_PW . '|'; + my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); + + my $server = { ils => $mocks->{ils} }; + undef $response; + $msg->handle_fee_paid( $server ); + + isnt( $response, undef, 'At least we got a response.' ); + + $schema->storage->txn_rollback; +}; + # Here is room for some more subtests # END of main code -- 2.24.3 (Apple Git-128)