Lines 338-351
subtest 'is_active' => sub {
Link Here
|
338 |
$patron->dateenrolled('2020-01-01')->store; |
338 |
$patron->dateenrolled('2020-01-01')->store; |
339 |
|
339 |
|
340 |
# Check lastseen, test days parameter |
340 |
# Check lastseen, test days parameter |
341 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 1 ); |
341 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login' ); |
342 |
$patron->update_lastseen('login'); |
342 |
$patron->update_lastseen('login'); |
343 |
is( $patron->is_active( { days => 1 } ), 1, 'Just logged in' ); |
343 |
is( $patron->is_active( { days => 1 } ), 1, 'Just logged in' ); |
344 |
my $ago = dt_from_string->subtract( days => 2 ); |
344 |
my $ago = dt_from_string->subtract( days => 2 ); |
345 |
$patron->lastseen($ago)->store; |
345 |
$patron->lastseen($ago)->store; |
346 |
is( $patron->is_active( { days => 1 } ), 0, 'Not active since yesterday' ); |
346 |
is( $patron->is_active( { days => 1 } ), 0, 'Not active since yesterday' ); |
347 |
is( $patron->is_active( { days => 3 } ), 1, 'Active within last 3 days' ); |
347 |
is( $patron->is_active( { days => 3 } ), 1, 'Active within last 3 days' ); |
348 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 0 ); |
348 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); |
349 |
is( $patron->is_active( { days => 3 } ), 0, 'Pref disabled' ); |
349 |
is( $patron->is_active( { days => 3 } ), 0, 'Pref disabled' ); |
350 |
|
350 |
|
351 |
# Look at holds, test with weeks |
351 |
# Look at holds, test with weeks |
Lines 1967-1973
subtest 'update_lastseen tests' => sub {
Link Here
|
1967 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
1967 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
1968 |
$cache->clear_from_cache($cache_key); |
1968 |
$cache->clear_from_cache($cache_key); |
1969 |
|
1969 |
|
1970 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
|
|
1971 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); |
1970 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); |
1972 |
|
1971 |
|
1973 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
1972 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
Lines 1977-1983
subtest 'update_lastseen tests' => sub {
Link Here
|
1977 |
|
1976 |
|
1978 |
$patron->update_lastseen('login'); |
1977 |
$patron->update_lastseen('login'); |
1979 |
$patron->_result()->discard_changes(); |
1978 |
$patron->_result()->discard_changes(); |
1980 |
isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' ); |
1979 |
isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivityTriggers contains values' ); |
1981 |
my $last_seen = $patron->lastseen; |
1980 |
my $last_seen = $patron->lastseen; |
1982 |
|
1981 |
|
1983 |
Time::Fake->offset( $now->epoch + 5 ); |
1982 |
Time::Fake->offset( $now->epoch + 5 ); |
Lines 2076-2087
subtest 'update_lastseen tests' => sub {
Link Here
|
2076 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' ); |
2075 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' ); |
2077 |
|
2076 |
|
2078 |
# Check that the preference takes effect |
2077 |
# Check that the preference takes effect |
2079 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
2078 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); |
2080 |
$patron->lastseen(undef)->store; |
2079 |
$patron->lastseen(undef)->store; |
2081 |
$cache->clear_from_cache($cache_key); |
2080 |
$cache->clear_from_cache($cache_key); |
2082 |
$patron->update_lastseen('login'); |
2081 |
$patron->update_lastseen('login'); |
2083 |
$patron->_result()->discard_changes(); |
2082 |
$patron->_result()->discard_changes(); |
2084 |
is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivity = 0' ); |
2083 |
is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivityTriggers is unset' ); |
2085 |
|
2084 |
|
2086 |
Time::Fake->reset; |
2085 |
Time::Fake->reset; |
2087 |
$schema->storage->txn_rollback; |
2086 |
$schema->storage->txn_rollback; |