@@ -, +, @@ message --- C4/SIP/Sip/MsgType.pm | 5 +++++ misc/sip_cli_emulator.pl | 13 ++++++++++++ t/db_dependent/SIP/Message.t | 41 +++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) --- a/C4/SIP/Sip/MsgType.pm +++ a/C4/SIP/Sip/MsgType.pm @@ -18,6 +18,7 @@ use Data::Dumper; use CGI qw ( -utf8 ); use C4::Auth qw(&check_api_auth); +use Koha::Patrons; use Koha::Patron::Attributes; use Koha::Items; @@ -1584,13 +1585,17 @@ my @message_type_names = ( sub send_acs_status { my ( $self, $server, $screen_msg, $print_line ) = @_; + my $msg = ACS_STATUS; ($server) or die "send_acs_status error: no \$server argument received"; my $account = $server->{account} or die "send_acs_status error: no 'account' in \$server object:\n" . Dumper($server); my $policy = $server->{policy} or die "send_acs_status error: no 'policy' in \$server object:\n" . Dumper($server); my $ils = $server->{ils} or die "send_acs_status error: no 'ils' in \$server object:\n" . Dumper($server); + my $sip_username = $server->{sip_username} or die "send_acs_status error: no 'sip_username' in \$server object:\n" . Dumper($server); my ( $online_status, $checkin_ok, $checkout_ok, $ACS_renewal_policy ); my ( $status_update_ok, $offline_ok, $timeout, $retries ); + my $sip_user = Koha::Patrons->find({ userid => $sip_username }); + die "send_acs_status error: sip_username cannot be found in DB or DB cannot be reached" unless $sip_user; $online_status = 'Y'; $checkout_ok = sipbool( $ils->checkout_ok ); --- a/misc/sip_cli_emulator.pl +++ a/misc/sip_cli_emulator.pl @@ -127,6 +127,12 @@ my $handlers = { location_code => $location_code, }, }, + sc_status_request => { + name => 'SC Status', + subroutine => \&build_sc_status_command_message, + parameters => { + }, + }, patron_status_request => { name => 'Patron Status Request', subroutine => \&build_patron_status_request_command_message, @@ -362,6 +368,12 @@ sub build_login_command_message { . build_field( FID_LOCATION_CODE, $location_code ); } +sub build_sc_status_command_message { + my ($params) = @_; + + return SC_STATUS . "0" . "030" . "2.00"; +} + sub build_patron_status_request_command_message { my ($params) = @_; @@ -653,6 +665,7 @@ Options: item_information patron_information patron_status_request + sc_status_request renew / } --- a/t/db_dependent/SIP/Message.t +++ a/t/db_dependent/SIP/Message.t @@ -21,7 +21,8 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; +use Test::Exception; use Test::MockObject; use Test::MockModule; use Test::Warn; @@ -337,6 +338,44 @@ subtest 'Patron info summary > 5 should not crash server' => sub { $schema->storage->txn_rollback; }; +subtest 'SC status tests' => sub { + + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + plan tests => 2; + + my $builder = t::lib::TestBuilder->new(); + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my $sip_user = $builder->build_object({ class => "Koha::Patrons" }); + + my ( $response, $findpatron ); + my $mocks = create_mocks( \$response, \$findpatron, \$branchcode ); + my $mockILS = $mocks->{ils}; + $mockILS->mock( 'checkout_ok', sub {1} ); + $mockILS->mock( 'checkin_ok', sub {1} ); + $mockILS->mock( 'status_update_ok', sub {1} ); + $mockILS->mock( 'offline_ok', sub {1} ); + $mockILS->mock( 'supports', sub {1} ); + my $server = Test::MockObject->new(); + $server->mock( 'get_timeout', sub {'100'}); + $server->{ils} = $mockILS; + $server->{sip_username} = $sip_user->userid; + $server->{account} = {}; + $server->{policy} = { renewal =>1,retries=>'000'}; + + my $siprequest = SC_STATUS . '0' . '030' . '2.00'; + my $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 ); + $msg->handle_sc_status( $server ); + + like( $response, qr/98YYYYYY100000[0-9 ]{19}.00AO|BXYYYYYYYYYYYYYYYY|/, 'At least we got a response.' ); + + $sip_user->delete; + + dies_ok{ $msg->handle_sc_status( $server ) } ,"Dies if sip user cannot be found"; + +}; + # Here is room for some more subtests # END of main code --