From c43919766bbd933047ff29f86aa410737fcaf087 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 8 Jul 2025 12:53:16 +0100 Subject: [PATCH] Bug 32934: Unit tests --- .../Circulation/OfflineCirculation.t | 39 +++++++++++++++++++ t/db_dependent/SIP/Transaction.t | 18 ++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation/OfflineCirculation.t b/t/db_dependent/Circulation/OfflineCirculation.t index ac74899d7b2..69e28e5878d 100755 --- a/t/db_dependent/Circulation/OfflineCirculation.t +++ b/t/db_dependent/Circulation/OfflineCirculation.t @@ -197,4 +197,43 @@ subtest "Bug 30114 - Koha offline circulation will always cancel the next hold w is( Koha::Holds->search( { biblionumber => $biblionumber } )->count, 2, "Still found two holds for the record" ); }; +subtest "Bug 32934: ProcessOfflineIssue returns checkout object for SIP no block due date" => sub { + plan tests => 4; + + $branch = $builder->build( { source => 'Branch' } )->{branchcode}; + $manager_id = $builder->build( { source => 'Borrower' } )->{borrowernumber}; + + my $borrower = $builder->build( + { + source => 'Borrower', + value => { branchcode => $branch } + } + ); + + my $biblio = $builder->build_sample_biblio; + my $item = $builder->build_sample_item( + { + biblionumber => $biblio->id, + library => $branch, + } + ); + + my $due_date = dt_from_string->add( days => 7 )->ymd; + + # Test ProcessOfflineIssue returns both message and checkout object + my ( $message, $checkout ) = ProcessOfflineIssue( + { + cardnumber => $borrower->{cardnumber}, + barcode => $item->barcode, + due_date => $due_date, + timestamp => dt_from_string + } + ); + + is( $message, "Success.", "ProcessOfflineIssue returns success message" ); + isa_ok( $checkout, 'Koha::Checkout', "ProcessOfflineIssue returns checkout object" ); + is( $checkout->borrowernumber, $borrower->{borrowernumber}, "Checkout has correct borrower" ); + is( $checkout->date_due->ymd, $due_date, "Checkout respects specified due_date" ); +}; + $schema->storage->txn_rollback; diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index a07033def5b..6bcac91bf5d 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -983,7 +983,7 @@ subtest do_checkout_with_patron_blocked => sub { }; subtest do_checkout_with_noblock => sub { - plan tests => 1; + plan tests => 3; my $mockILS = Test::MockObject->new; my $server = { ils => $mockILS }; @@ -1033,6 +1033,22 @@ subtest do_checkout_with_noblock => sub { $patron->checkouts->count, 1, 'No Block checkout was performed for debarred patron' ); + + # Test Bug 32934: SIP checkout with no_block_due_date should honor the specified due date + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + my $sip_item_2 = C4::SIP::ILS::Item->new( $item->barcode ); + my $transaction = C4::SIP::ILS::Transaction::Checkout->new(); + + $transaction->patron($sip_patron); + $transaction->item($sip_item_2); + + # Set no_block_due_date to test the fix + my $expected_due_date = '20250115'; + my $checkout_result = $transaction->do_checkout($expected_due_date); + + my $checkout_obj = $patron->checkouts->find({ itemnumber => $item->itemnumber }); + isnt( $checkout_obj, undef, 'Checkout object exists after no block checkout' ); + like( $checkout_obj->date_due->ymd(''), qr/^20250115/, 'No block due date is honored in SIP checkout' ); }; subtest do_checkout_with_holds => sub { -- 2.50.0