From 0147ae8485ca161250efa5213eef137d47248964 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 12 Jul 2022 16:22:46 +0100 Subject: [PATCH] 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 --- t/db_dependent/Koha/Hold.t | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index 8c32bda3f7..db5189db40 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -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; -- 2.20.1