Bug 36605: [23.05.x] Add update_lastseen to handle_patron_status for SIP
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
7578b93c12
commit
b05d87a703
2 changed files with 54 additions and 2 deletions
|
@ -503,6 +503,7 @@ sub handle_patron_status {
|
||||||
|
|
||||||
$ils->check_inst_id( $fields->{ (FID_INST_ID) }, "handle_patron_status" );
|
$ils->check_inst_id( $fields->{ (FID_INST_ID) }, "handle_patron_status" );
|
||||||
$patron = $ils->find_patron( $fields->{ (FID_PATRON_ID) } );
|
$patron = $ils->find_patron( $fields->{ (FID_PATRON_ID) } );
|
||||||
|
$patron->update_lastseen() if $patron;
|
||||||
$resp = build_patron_status( $patron, $lang, $fields, $server );
|
$resp = build_patron_status( $patron, $lang, $fields, $server );
|
||||||
$self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} );
|
$self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} );
|
||||||
return (PATRON_STATUS_REQ);
|
return (PATRON_STATUS_REQ);
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||||
|
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
use Test::More tests => 17;
|
use Test::More tests => 18;
|
||||||
use Test::Exception;
|
use Test::Exception;
|
||||||
use Test::MockObject;
|
use Test::MockObject;
|
||||||
use Test::MockModule;
|
use Test::MockModule;
|
||||||
|
@ -196,7 +196,7 @@ subtest 'hold_patron_name() tests' => sub {
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'Lastseen response' => sub {
|
subtest 'Lastseen response patron_info' => sub {
|
||||||
|
|
||||||
my $schema = Koha::Database->new->schema;
|
my $schema = Koha::Database->new->schema;
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
@ -247,6 +247,57 @@ subtest 'Lastseen response' => sub {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
subtest 'Lastseen response patron status' => 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 $seen_patron = $builder->build({
|
||||||
|
source => 'Borrower',
|
||||||
|
value => {
|
||||||
|
lastseen => '2001-01-01',
|
||||||
|
password => hash_password( PATRON_PW ),
|
||||||
|
branchcode => $branchcode,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
my $cardnum = $seen_patron->{cardnumber};
|
||||||
|
my $sip_patron = C4::SIP::ILS::Patron->new( $cardnum );
|
||||||
|
$findpatron = $sip_patron;
|
||||||
|
|
||||||
|
my $siprequest = PATRON_STATUS_REQ. 'engYYYYMMDDZZZZHHMMSS'.
|
||||||
|
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;
|
||||||
|
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '' );
|
||||||
|
$msg->handle_patron_status( $server );
|
||||||
|
|
||||||
|
isnt( $response, undef, 'At least we got a response.' );
|
||||||
|
my $respcode = substr( $response, 0, 2 );
|
||||||
|
is( $respcode, PATRON_STATUS_RESP, 'Response code fine' );
|
||||||
|
$seen_patron = Koha::Patrons->find({ cardnumber => $seen_patron->{cardnumber} });
|
||||||
|
is( output_pref({str => $seen_patron->lastseen(), dateonly => 1}), output_pref({str => '2001-01-01', dateonly => 1}),'Last seen not updated if not tracking patrons');
|
||||||
|
undef $response;
|
||||||
|
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' );
|
||||||
|
$msg->handle_patron_status( $server );
|
||||||
|
|
||||||
|
isnt( $response, undef, 'At least we got a response.' );
|
||||||
|
$respcode = substr( $response, 0, 2 );
|
||||||
|
is( $respcode, PATRON_STATUS_RESP, 'Response code fine' );
|
||||||
|
$seen_patron = Koha::Patrons->find({ cardnumber => $seen_patron->cardnumber() });
|
||||||
|
is( output_pref({str => $seen_patron->lastseen(), dateonly => 1}), output_pref({dt => dt_from_string(), dateonly => 1}),'Last seen updated if tracking patrons');
|
||||||
|
$schema->storage->txn_rollback;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
subtest "Test patron_status_string" => sub {
|
subtest "Test patron_status_string" => sub {
|
||||||
my $schema = Koha::Database->new->schema;
|
my $schema = Koha::Database->new->schema;
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
Loading…
Reference in a new issue