Bug 31447: Add unit tests
authorEmmi Takkinen <emmi.takkinen@koha-suomi.fi>
Thu, 3 Nov 2022 12:40:40 +0000 (14:40 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 14 Nov 2022 12:25:10 +0000 (09:25 -0300)
To test prove t/db_dependent/Circulation.t

Sponsored-by: Koha-Suomi Oy
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
t/db_dependent/Circulation.t

index b783a82..339f5b6 100755 (executable)
@@ -18,7 +18,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 63;
+use Test::More tests => 64;
 use Test::Exception;
 use Test::MockModule;
 use Test::Deep qw( cmp_deeply );
@@ -5693,6 +5693,46 @@ subtest "GetSoonestRenewDate tests" => sub {
     );
 };
 
+subtest "CanBookBeIssued + needsconfirmation message" => sub {
+    plan tests => 4;
+
+    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
+    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
+    my $biblioitem = $builder->build_object({ class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber }});
+    my $item = $builder->build_object({ class => 'Koha::Items' , value => { biblionumber => $biblio->biblionumber }});
+
+    my $hold = $builder->build_object({ class => 'Koha::Holds', value => {
+        biblionumber => $item->biblionumber,
+        branchcode => $library->branchcode,
+        itemnumber => undef,
+        itemtype => undef,
+        priority => 1,
+        found => undef,
+        suspend => 0,
+        item_group_id => $item->item_group
+    }});
+
+    my ( $error, $needsconfirmation, $alerts, $messages );
+
+    ( $error, $needsconfirmation, $alerts, $messages ) = CanBookBeIssued( $patron, $item->barcode );
+    is($needsconfirmation->{resbranchcode}, $hold->branchcode, "Branchcodes match when hold exists.");
+
+    $hold->priority(0)->store();
+
+    $hold->found("W")->store();
+    ( $error, $needsconfirmation, $alerts, $messages ) = CanBookBeIssued( $patron, $item->barcode );
+    is($needsconfirmation->{resbranchcode}, $hold->branchcode, "Branchcodes match when hold is waiting.");
+
+    $hold->found("T")->store();
+    ( $error, $needsconfirmation, $alerts, $messages ) = CanBookBeIssued( $patron, $item->barcode );
+    is($needsconfirmation->{resbranchcode}, $hold->branchcode, "Branchcodes match when hold is being transferred.");
+
+    $hold->found("P")->store();
+    ( $error, $needsconfirmation, $alerts, $messages ) = CanBookBeIssued( $patron, $item->barcode );
+    is($needsconfirmation->{resbranchcode}, $hold->branchcode, "Branchcodes match when hold is being processed.");
+};
+
 $schema->storage->txn_rollback;
 C4::Context->clear_syspref_cache();
 $branches = Koha::Libraries->search();