Bug 31086: (QA follow-up) Add unit tests

This patch adds the unit tests for the change to Koha::Hold::store.

We test for and catch the exception introduced for both the create and
update cases.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit f0685f0f40)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2022-07-12 16:22:46 +01:00 committed by Lucas Gass
parent 51f33cbc20
commit bc95ffa3e3

View file

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 6;
use Test::More tests => 7;
use Test::Exception;
use Test::MockModule;
@ -36,6 +36,36 @@ use Koha::Old::Holds;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
subtest 'store() tests' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $item = $builder->build_sample_item;
throws_ok {
Koha::Hold->new(
{
borrowernumber => $patron->borrowernumber,
biblionumber => $item->biblionumber,
priority => 1,
itemnumber => $item->itemnumber,
}
)->store
}
'Koha::Exceptions::Hold::MissingPickupLocation',
'Exception thrown because branchcode was not passed';
my $hold = $builder->build_object( { class => 'Koha::Holds' } );
throws_ok {
$hold->branchcode(undef)->store;
}
'Koha::Exceptions::Hold::MissingPickupLocation',
'Exception thrown if one tries to set branchcode to null';
$schema->storage->txn_rollback;
};
subtest 'fill() tests' => sub {
plan tests => 13;