View | Details | Raw Unified | Return to bug 40866
Collapse All | Expand All

(-)a/t/db_dependent/Circulation.t (-1 / +20 lines)
Lines 19-25 use Modern::Perl; Link Here
19
use utf8;
19
use utf8;
20
20
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 82;
22
use Test::More tests => 83;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Deep qw( cmp_deeply );
25
use Test::Deep qw( cmp_deeply );
Lines 8005-8010 subtest 'Bug 9762: AddRenewal override JSON logging' => sub { Link Here
8005
    is_deeply( $log_data->{forced},        ['TOO_MUCH'],                      'Forced overrides logged correctly' );
8005
    is_deeply( $log_data->{forced},        ['TOO_MUCH'],                      'Forced overrides logged correctly' );
8006
};
8006
};
8007
8007
8008
subtest 'Bug 40866: CanBookBeIssued returns correct number of values' => sub {
8009
    plan tests => 2;
8010
8011
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
8012
    my $patron =
8013
        $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library->branchcode } } );
8014
    my $item = $builder->build_sample_item( { library => $library->branchcode } );
8015
8016
    t::lib::Mocks::mock_userenv( { patron => $patron, branchcode => $library->branchcode } );
8017
8018
    # CanBookBeIssued should return exactly 4 values after Bug 40866 cleanup
8019
    # (issuingimpossible, needsconfirmation, alerts, messages)
8020
    # The 5th return value (@message_log) from the original Bug 9762 implementation was removed
8021
    my @result = C4::Circulation::CanBookBeIssued( $patron, $item->barcode );
8022
8023
    is( scalar @result, 4, 'CanBookBeIssued returns exactly 4 values' );
8024
    ok( ref( $result[0] ) eq 'HASH', 'First return value is issuingimpossible hashref' );
8025
};
8026
8008
$schema->storage->txn_rollback;
8027
$schema->storage->txn_rollback;
8009
C4::Context->clear_syspref_cache();
8028
C4::Context->clear_syspref_cache();
8010
$branches = Koha::Libraries->search();
8029
$branches = Koha::Libraries->search();
(-)a/t/db_dependent/Reserves.t (-1 / +91 lines)
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
};
(-)a/t/db_dependent/api/v1/holds.t (-2 / +71 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 18;
20
use Test::More tests => 19;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Mojo;
23
use Test::Mojo;
Lines 25-30 use t::lib::TestBuilder; Link Here
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
26
27
use DateTime;
27
use DateTime;
28
use JSON       qw( from_json );
28
use Mojo::JSON qw(encode_json);
29
use Mojo::JSON qw(encode_json);
29
30
30
use C4::Context;
31
use C4::Context;
Lines 32-37 use Koha::Patrons; Link Here
32
use C4::Reserves qw( AddReserve CanItemBeReserved CanBookBeReserved );
33
use C4::Reserves qw( AddReserve CanItemBeReserved CanBookBeReserved );
33
use C4::Items;
34
use C4::Items;
34
35
36
use Koha::ActionLogs;
35
use Koha::Database;
37
use Koha::Database;
36
use Koha::DateUtils qw( dt_from_string output_pref );
38
use Koha::DateUtils qw( dt_from_string output_pref );
37
use Koha::Biblios;
39
use Koha::Biblios;
Lines 1885-1887 subtest 'PUT /holds/{hold_id}/lowest_priority tests' => sub { Link Here
1885
1887
1886
    $schema->storage->txn_rollback;
1888
    $schema->storage->txn_rollback;
1887
};
1889
};
1888
- 
1890
1891
subtest 'Bug 40866: API hold creation with override logs confirmations' => sub {
1892
    plan tests => 6;
1893
1894
    $schema->storage->txn_begin;
1895
1896
    my $librarian = $builder->build_object(
1897
        {
1898
            class => 'Koha::Patrons',
1899
            value => { flags => 1 }
1900
        }
1901
    );
1902
    my $password = 'thePassword123';
1903
    $librarian->set_password( { password => $password, skip_validation => 1 } );
1904
    my $userid = $librarian->userid;
1905
1906
    my $patron = $builder->build_object(
1907
        {
1908
            class => 'Koha::Patrons',
1909
            value => { flags => 0 }
1910
        }
1911
    );
1912
1913
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1914
    my $biblio  = $builder->build_sample_biblio;
1915
1916
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 );
1917
    t::lib::Mocks::mock_preference( 'HoldsLog',                1 );
1918
1919
    # Clear any existing logs
1920
    Koha::ActionLogs->search( { module => 'HOLDS', action => 'CREATE' } )->delete;
1921
1922
    my $post_data = {
1923
        patron_id         => $patron->id,
1924
        biblio_id         => $biblio->id,
1925
        pickup_library_id => $library->branchcode,
1926
    };
1927
1928
    # Create hold with override
1929
    my $hold_id =
1930
        $t->post_ok( "//$userid:$password@/api/v1/holds" => { 'x-koha-override' => 'any' } => json => $post_data )
1931
        ->status_is(201)->tx->res->json->{hold_id};
1932
1933
    ok( $hold_id, 'Hold created via API with override' );
1934
1935
    # Verify the hold was logged with override information
1936
    my $logs = Koha::ActionLogs->search(
1937
        {
1938
            module => 'HOLDS',
1939
            action => 'CREATE',
1940
            object => $hold_id
1941
        },
1942
        { order_by => { -desc => 'timestamp' } }
1943
    );
1944
1945
    is( $logs->count, 1, 'One log entry created for API hold with override' );
1946
1947
    my $log      = $logs->next;
1948
    my $log_data = eval { from_json( $log->info ) };
1949
    ok( !$@, 'Log info is valid JSON' );
1950
    is_deeply(
1951
        $log_data->{confirmations},
1952
        ['HOLD_POLICY_OVERRIDE'],
1953
        'HOLD_POLICY_OVERRIDE logged in confirmations array'
1954
    );
1955
1956
    $schema->storage->txn_rollback;
1957
};

Return to bug 40866