Bug 21652: Simplify code

And add a test.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit a96c944c17)

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2022-01-20 11:20:49 +01:00 committed by Andrew Fuerste-Henry
parent 96f3f86882
commit d5ecd99396
2 changed files with 7 additions and 14 deletions

View File

@ -180,18 +180,11 @@ sub set_waiting {
$self->priority(0);
my $waiting_date;
my $today = dt_from_string();
if ( $self->waitingdate ) {
$waiting_date = $self->waitingdate;
} else {
$waiting_date = $today->ymd;
}
my $values = {
found => 'W',
waitingdate => $waiting_date,
( !$self->waitingdate ? ( waitingdate => $today->ymd ) : () ),
desk_id => $desk_id,
};

View File

@ -227,21 +227,21 @@ subtest "store() tests" => sub {
subtest "set_waiting() tests" => sub {
plan tests => 1;
plan tests => 2;
$schema->storage->txn_begin();
# Disable logging
t::lib::Mocks::mock_preference( 'HoldsLog', 0 );
my $hold = $builder->build_object({ class => 'Koha::Holds' });
$hold->waitingdate('2021-01-01');
$hold->set_waiting();
is($hold->waitingdate, '2021-01-01', "Setting waiting when already waiting should not update waitingdate");
is($hold->waitingdate,'2021-01-01',"Setting waiting when already waiting should not update waitingdate");
$hold->waitingdate(undef)->store;
$hold->set_waiting();
isnt($hold->waitingdate, undef, "Setting waiting when not waiting already should update waitingdate");
$schema->storage->txn_rollback();
};
subtest "delete() tests" => sub {