Bug 23426: (follow-up) Add tests

Test plan:
[1] Prove t/db_dependent/SIP/Message.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
EDIT: Tidied inline.
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit efe0b8c627)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jan Kissig 2024-07-22 12:41:40 +02:00 committed by Lucas Gass
parent d140000c98
commit 3dec3a9cb8
1 changed files with 85 additions and 1 deletions

View File

@ -21,7 +21,7 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 21;
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;