Bug 40517: Add unit tests

Run the updated test file:
prove ./t/db_dependent/Koha/Patron.t

Relevant tests worth running to ensure no regressions are added to existing covered functionality:
prove ./t/db_dependent/Circulation*
prove ./t/db_dependent/Hold*
prove ./t/db_dependent/Reserves*

Test plan, k-t-d:
1) Apply patches, enable DisplayAddHoldGroups system preference
2) Do a search for 'test':
<staff_url>/cgi-bin/koha/catalogue/search.pl?q=test
3) Click the 'Select all' link at the top of the search results, click the 'Place hold' button.
4) Enter the 'koha' user
5) Pick a pickup location for each of the holds and click 'Place holds'.
6) Visit the 'koha' patron:
<staff_url>/cgi-bin/koha/members/moremember.pl?borrowernumber=51
7) Click the 'holds' tab. Notice a new 'Group selected' button now exists
8) Pick any number of holds (more than 2) and click the 'Group selected' button. Confirm
9) Notice the hold group shows '1'. If you click on it you're presented the hold group modal.
10) Group multiple holds multiple times.
11) Notice you can't group a hold that has already been found.
12) Notice you can't click the 'Group selected' button unless at least 2 holds are selected.
13) Notice a hold group is deleted if left with 0 or 1 hold e.g. make a group of 2 holds, cancel 1, notice the remaining hold is left without a group.

prove t/db_dependent/api/v1/patrons_hold_groups.t
prove t/db_dependent/Koha/Patron.t

Signed-off-by: Anneli <anneli.osterman@koha-suomi.fi>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Pedro Amorim 2025-07-25 13:59:23 +00:00 committed by Lucas Gass
parent 1ccc10c058
commit edd318fa91
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 89 additions and 1 deletions

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 44;
use Test::More tests => 45;
use Test::NoWarnings;
use Test::Exception;
use Test::Warn;
@ -3364,3 +3364,91 @@ subtest 'reset_2fa() tests' => sub {
$schema->storage->txn_rollback;
};
subtest "create_hold_group, hold_groups, visual_hold_group_id tests" => sub {
plan tests => 13;
$schema->storage->txn_begin;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $hold1 = $builder->build_object(
{
class => 'Koha::Holds',
value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber }
}
);
my $hold2 = $builder->build_object(
{
class => 'Koha::Holds',
value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber }
}
);
my $hold3 = $builder->build_object(
{
class => 'Koha::Holds',
value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber }
}
);
my $hold4 = $builder->build_object(
{
class => 'Koha::Holds',
value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber }
}
);
my $hold5 = $builder->build_object(
{
class => 'Koha::Holds',
value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber }
}
);
my $hold6 = $builder->build_object(
{
class => 'Koha::Holds',
value => { hold_group_id => undef, found => undef, borrowernumber => $patron->borrowernumber }
}
);
my $patron_hold_groups = $patron->hold_groups;
is( $patron_hold_groups->count, 0, 'Patron does not have any hold groups' );
# Create 1st hold group
$patron->create_hold_group( [ $hold1->reserve_id, $hold2->reserve_id, $hold3->reserve_id ] );
is( $patron_hold_groups->count, 1, 'Patron has one hold group' );
my $hold_group = $patron->hold_groups->as_list->[0];
is( $hold_group->visual_hold_group_id, 1, 'Visual hold group id is 1' );
is( $hold_group->hold_group_id, $hold1->get_from_storage->hold_group_id, 'hold1 added to hold_group' );
is( $hold_group->hold_group_id, $hold2->get_from_storage->hold_group_id, 'hold2 added to hold_group' );
is( $hold_group->hold_group_id, $hold3->get_from_storage->hold_group_id, 'hold3 added to hold_group' );
# Create 2nd hold group
$patron->create_hold_group( [ $hold4->reserve_id, $hold5->reserve_id ] );
is( $patron_hold_groups->count, 2, 'Patron has two hold groups' );
my $second_hold_group = $patron->hold_groups->as_list->[1];
is( $second_hold_group->visual_hold_group_id, 2, 'Visual hold group id is 2' );
is(
$second_hold_group->hold_group_id, $hold4->get_from_storage->hold_group_id,
'hold4 added to second hold_group'
);
is(
$second_hold_group->hold_group_id, $hold5->get_from_storage->hold_group_id,
'hold5 added to second hold_group'
);
$hold3->get_from_storage->fill();
is( $patron->get_from_storage->hold_groups->count, 1, 'Patron only has one hold group again' );
$hold4->get_from_storage->cancel();
is( $patron->get_from_storage->hold_groups->count, 0, 'Patron does not have any hold groups again' );
# Create 3rd hold group
$patron->create_hold_group( [ $hold5->reserve_id, $hold6->reserve_id ] );
my $third_hold_group = $patron->hold_groups->as_list->[0];
is( $third_hold_group->visual_hold_group_id, 1, 'Visual hold group id is 1' );
$schema->storage->txn_rollback;
};