|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 70; |
20 |
use Test::More tests => 71; |
| 21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
|
Lines 25-30
use Test::Warn;
Link Here
|
| 25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
| 26 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
| 27 |
|
27 |
|
|
|
28 |
use JSON qw( from_json ); |
| 28 |
use MARC::Record; |
29 |
use MARC::Record; |
| 29 |
use DateTime::Duration; |
30 |
use DateTime::Duration; |
| 30 |
|
31 |
|
|
Lines 2004-2006
subtest 'CheckReserves() item type tests' => sub {
Link Here
|
| 2004 |
|
2005 |
|
| 2005 |
$schema->storage->txn_rollback; |
2006 |
$schema->storage->txn_rollback; |
| 2006 |
}; |
2007 |
}; |
|
|
2008 |
|
| 2009 |
subtest 'Bug 40866: AddReserve override JSON logging' => sub { |
| 2010 |
plan tests => 8; |
| 2011 |
|
| 2012 |
$schema->storage->txn_begin; |
| 2013 |
|
| 2014 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 2015 |
my $patron = $builder->build_object( |
| 2016 |
{ |
| 2017 |
class => 'Koha::Patrons', |
| 2018 |
value => { branchcode => $library->branchcode } |
| 2019 |
} |
| 2020 |
); |
| 2021 |
my $biblio = $builder->build_sample_biblio(); |
| 2022 |
my $item = $builder->build_sample_item( |
| 2023 |
{ |
| 2024 |
library => $library->branchcode, |
| 2025 |
biblionumber => $biblio->biblionumber |
| 2026 |
} |
| 2027 |
); |
| 2028 |
|
| 2029 |
t::lib::Mocks::mock_userenv( { patron => $patron, branchcode => $library->branchcode } ); |
| 2030 |
t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); |
| 2031 |
|
| 2032 |
# Clear any existing logs |
| 2033 |
Koha::ActionLogs->search( { module => 'HOLDS', action => 'CREATE' } )->delete; |
| 2034 |
|
| 2035 |
# Test 1: Normal hold without overrides - should log hold ID only |
| 2036 |
my $hold_id = C4::Reserves::AddReserve( |
| 2037 |
{ |
| 2038 |
branchcode => $library->branchcode, |
| 2039 |
borrowernumber => $patron->borrowernumber, |
| 2040 |
biblionumber => $biblio->biblionumber, |
| 2041 |
priority => 1, |
| 2042 |
} |
| 2043 |
); |
| 2044 |
ok( $hold_id, 'Hold created successfully' ); |
| 2045 |
|
| 2046 |
my $logs = Koha::ActionLogs->search( |
| 2047 |
{ |
| 2048 |
module => 'HOLDS', |
| 2049 |
action => 'CREATE', |
| 2050 |
object => $hold_id |
| 2051 |
}, |
| 2052 |
{ order_by => { -desc => 'timestamp' } } |
| 2053 |
); |
| 2054 |
is( $logs->count, 1, 'One log entry created for normal hold' ); |
| 2055 |
my $log = $logs->next; |
| 2056 |
is( $log->info, $hold_id, 'Normal hold logs hold ID only' ); |
| 2057 |
|
| 2058 |
# Cancel the hold for next test |
| 2059 |
my $hold = Koha::Holds->find($hold_id); |
| 2060 |
$hold->cancel; |
| 2061 |
|
| 2062 |
# Test 2: Hold with override confirmation - should log JSON with confirmations |
| 2063 |
my $hold_id2 = C4::Reserves::AddReserve( |
| 2064 |
{ |
| 2065 |
branchcode => $library->branchcode, |
| 2066 |
borrowernumber => $patron->borrowernumber, |
| 2067 |
biblionumber => $biblio->biblionumber, |
| 2068 |
priority => 1, |
| 2069 |
confirmations => ['HOLD_POLICY_OVERRIDE'], |
| 2070 |
forced => [] |
| 2071 |
} |
| 2072 |
); |
| 2073 |
ok( $hold_id2, 'Hold with override created successfully' ); |
| 2074 |
|
| 2075 |
$logs = Koha::ActionLogs->search( |
| 2076 |
{ |
| 2077 |
module => 'HOLDS', |
| 2078 |
action => 'CREATE', |
| 2079 |
object => $hold_id2 |
| 2080 |
}, |
| 2081 |
{ order_by => { -desc => 'timestamp' } } |
| 2082 |
); |
| 2083 |
is( $logs->count, 1, 'One log entry created for override hold' ); |
| 2084 |
$log = $logs->next; |
| 2085 |
|
| 2086 |
my $log_data = eval { from_json( $log->info ) }; |
| 2087 |
ok( !$@, 'Log info is valid JSON' ); |
| 2088 |
ok( exists $log_data->{confirmations}, 'JSON contains confirmations array' ); |
| 2089 |
is_deeply( |
| 2090 |
$log_data->{confirmations}, |
| 2091 |
['HOLD_POLICY_OVERRIDE'], |
| 2092 |
'Confirmations logged correctly' |
| 2093 |
); |
| 2094 |
|
| 2095 |
$schema->storage->txn_rollback; |
| 2096 |
}; |