From 7cf6e23598fc780d431bc6d3844fff4a2bcf53b0 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Thu, 10 Mar 2022 13:51:58 +0000
Subject: [PATCH] Bug 29936: Add unit tests

This patch adds a unit test for the new functionality introduced with
holds_get_captured allowing for holds to still be highlighted to patrons
at checkin but not mark them as found/transfered in the system.

Sponsored-by: Cheshire Libraries Shared Services
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
---
 t/db_dependent/SIP/Message.t | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t
index bc13c3bf25..c43a3fdc6c 100755
--- a/t/db_dependent/SIP/Message.t
+++ b/t/db_dependent/SIP/Message.t
@@ -80,7 +80,7 @@ subtest 'Checkout V2' => sub {
 subtest 'Checkin V2' => sub {
     my $schema = Koha::Database->new->schema;
     $schema->storage->txn_begin;
-    plan tests => 35;
+    plan tests => 39;
     $C4::SIP::Sip::protocol_version = 2;
     test_checkin_v2();
     $schema->storage->txn_rollback;
@@ -813,11 +813,23 @@ sub test_checkin_v2 {
     $msg->handle_checkin( $server );
     is( substr($response,2,1), '0', 'OK flag is false when we check in an item on hold and we do not allow it' );
     is( substr($response,5,1), 'Y', 'Alert flag is set' );
-    check_field( $respcode, $response, FID_SCREEN_MSG, 'Item is on hold, please return to circulation desk', 'Screen message is correct' );
     is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 1, "Item was not checked in");
-    $hold->delete();
+    $hold->discard_changes;
+    is( $hold->found, undef, "Hold was not marked as found by SIP when holds_block_checkin enabled");
     $server->{account}->{holds_block_checkin} = 0;
 
+    # Test account option holds_get_captured that automatically sets the hold as found for a hold and possibly sets it to in transit
+    $server->{account}->{holds_get_captured} = 0;
+    undef $response;
+    $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
+    $msg->handle_checkin( $server );
+    is( substr($response,2,1), '1', 'OK flag is true when we check in an item on hold and we allow it but do not capture it' );
+    is( substr($response,5,1), 'Y', 'Alert flag is set' );
+    is( Koha::Checkouts->search({ itemnumber => $item_object->id })->count, 0, "Item was checked in");
+    $hold->discard_changes;
+    is( $hold->found, undef, "Hold was not marked as found by SIP when holds_get_captured disabled");
+    $hold->delete();
+    $server->{account}->{holds_get_captured} = 1;
 }
 
 sub test_hold_patron_bcode {
-- 
2.20.1