Bug 24966: Add unit tests
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 10 Apr 2020 10:43:51 +0000 (06:43 -0400)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 14 Apr 2020 07:27:14 +0000 (08:27 +0100)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/SIP/Message.t

index 2cdeba7..bc8e87a 100755 (executable)
@@ -21,7 +21,7 @@
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Test::More tests => 4;
+use Test::More tests => 5;
 use Test::MockObject;
 use Test::MockModule;
 use Test::Warn;
@@ -73,6 +73,15 @@ subtest 'Checkin V2' => sub {
     $schema->storage->txn_rollback;
 };
 
+subtest 'Test hold_patron_bcode' => sub {
+    my $schema = Koha::Database->new->schema;
+    $schema->storage->txn_begin;
+    plan tests => 2;
+    $C4::SIP::Sip::protocol_version = 2;
+    test_hold_patron_bcode();
+    $schema->storage->txn_rollback;
+};
+
 subtest 'Lastseen response' => sub {
 
     my $schema = Koha::Database->new->schema;
@@ -468,6 +477,27 @@ sub test_checkin_v2 {
         'Issue record is gone now' );
 }
 
+sub test_hold_patron_bcode {
+    my $builder = t::lib::TestBuilder->new();
+    my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
+    my ( $response, $findpatron );
+    my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
+
+    my $item = $builder->build({
+        source => 'Item',
+        value => { damaged => 0, withdrawn => 0, itemlost => 0, restricted => 0, homebranch => $branchcode, holdingbranch => $branchcode },
+    });
+    my $item_object = Koha::Items->find( $item->{itemnumber} );
+
+    my $server = { ils => $mocks->{ils} };
+    my $sip_item = C4::SIP::ILS::Item->new( $item->{barcode} );
+
+    is( $sip_item->hold_patron_bcode, q{}, "SIP item with no hold returns empty string" );
+
+    my $resp .= C4::SIP::Sip::maybe_add( FID_CALL_NUMBER, $sip_item->hold_patron_bcode, $server );
+    is( $resp, q{}, "maybe_add returns empty string for SIP item with no hold returns empty string" );
+}
+
 # Helper routines
 
 sub create_mocks {