From efe0b8c627d8fc7396c980b458e6ac7469fe0867 Mon Sep 17 00:00:00 2001 From: Jan Kissig Date: Mon, 22 Jul 2024 12:41:40 +0200 Subject: [PATCH] Bug 23426: (follow-up) Add tests Test plan: [1] Prove t/db_dependent/SIP/Message.t Signed-off-by: Marcel de Rooy EDIT: Tidied inline. Signed-off-by: Katrin Fischer --- t/db_dependent/SIP/Message.t | 86 +++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t index b7c01b4f71..7975619b07 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 => 19; +use Test::More tests => 20; use Test::Exception; use Test::MockObject; use Test::MockModule; @@ -249,6 +249,90 @@ subtest 'Lastseen response patron info' => sub { }; +subtest 'Fine items, currency, start and end item response in patron info' => sub { + + plan tests => 6; + + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + my $builder = t::lib::TestBuilder->new(); + my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; + my ( $response, $findpatron ); + my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); + my $patron_with_fines = $builder->build( + { + source => 'Borrower', + value => { + password => hash_password(PATRON_PW), + branchcode => $branchcode, + }, + } + ); + + # SIP2 currency field is limited to 3 chars + my $currency = substr Koha::Acquisition::Currencies->get_active->currency, + 0, 3; + + my $account = Koha::Account->new( { patron_id => $patron_with_fines->{borrowernumber} } ); + + my $amount1 = '1.00'; + my $amount2 = '2.00'; + my $amount3 = '3.00'; + + my $debt1 = $account->add_debit( { type => 'ACCOUNT', amount => $amount1, interface => 'commandline' } ); + my $debt2 = $account->add_debit( { type => 'ACCOUNT', amount => $amount2, interface => 'commandline' } ); + my $debt3 = $account->add_debit( { type => 'ACCOUNT', amount => $amount3, interface => 'commandline' } ); + + my $cardnum = $patron_with_fines->{cardnumber}; + my $sip_patron = C4::SIP::ILS::Patron->new($cardnum); + $findpatron = $sip_patron; + + my $siprequest = + PATRON_INFO + . 'engYYYYMMDDZZZZHHMMSS' + . ' Y ' + . FID_INST_ID + . $branchcode . '|' + . FID_PATRON_ID + . $cardnum . '|' + . FID_PATRON_PWD + . PATRON_PW . '|' + . FID_START_ITEM . '2|' + . FID_END_ITEM . '3|'; + my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); + + my $server = { ils => $mocks->{ils} }; + undef $response; + $msg->handle_patron_info($server); + + isnt( $response, undef, 'At least we got a response.' ); + my $respcode = substr( $response, 0, 2 ); + is( $respcode, PATRON_INFO_RESP, 'Response code fine' ); + + check_field( + $respcode, $response, FID_CURRENCY, $currency, + 'Verified active currency' + ); + + # the following checks apply to fields which can occur several times + isnt( + $response =~ /\|${\FID_FINE_ITEMS} $amount1/, + 1, 'Verified fine item 1 is not in response' + ); + is( + $response =~ /\|${\FID_FINE_ITEMS}\s$amount2/, + 1, 'Verified fine item 2' + ); + is( + $response =~ /\|${\FID_FINE_ITEMS}\s$amount3/, + 1, 'Verified fine item 3' + ); + + $schema->storage->txn_rollback; +}; + + subtest "Test patron_status_string" => sub { my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; -- 2.39.5