From 4b37f32c87c7c8d8b4e5a0fb0d99588f5aa55c9d Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 26 Sep 2024 13:00:26 +0000 Subject: [PATCH] Bug 33292: Add unit tests Test plan: 1) In KTD, set ClaimReturnedLostValue to any value 2) Checkout an item to a patron 3) Add a manual invoice to that patron's account against that item barcode 4) In the patron's checkouts table, click the Claim returned button 5) The checkbox will have the option to "Refund previous lost fee" 6) Tick this box and submit 7) Have a look at the patron's transactions. There will now be a new line refunding the lost fee from step 3 8) Run the unit tests prove t/db_dependent/Circulation/ReturnClaims.t prove t/db_dependent/api/v1/return_claims.t Signed-off-by: Kristi Krueger Signed-off-by: Lucas Gass Signed-off-by: Katrin Fischer --- t/db_dependent/Circulation/ReturnClaims.t | 42 ++++++++++++++++++++++- t/db_dependent/api/v1/return_claims.t | 3 ++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation/ReturnClaims.t b/t/db_dependent/Circulation/ReturnClaims.t index 2bb2a5c437..e1b4409f6e 100755 --- a/t/db_dependent/Circulation/ReturnClaims.t +++ b/t/db_dependent/Circulation/ReturnClaims.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::MockModule; use Test::Warn; @@ -143,6 +143,46 @@ subtest 'Test Koha::Checkout::claim_returned, mark as returned' => sub { is( $checkout2->id, $checkout->id, "Checkout was found in the old_issues table"); }; +subtest 'Test Koha::Checkout::claim_returned, should refund a previous lost fee if refund_lost_fee is set' => sub { + plan tests => 4; + + t::lib::Mocks::mock_preference( 'ClaimReturnedLostValue', 1 ); + t::lib::Mocks::mock_preference( 'MarkLostItemsAsReturned', q{claim_returned} ); + my $item = $builder->build_sample_item; + my $itemnumber = $item->itemnumber; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $checkout = AddIssue( $patron, $item->barcode ); + + my $line = Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + itemnumber => $itemnumber, + debit_type_code => "LOST", + status => "NULL", + amount => 10, + amountoutstanding => 10, + interface => 'commandline', + } + )->store; + + my $claim = $checkout->claim_returned( + { + created_by => $patron->borrowernumber, + notes => "Test note", + refund_lost_fee => 1 + } + ); + + my $updated_line = Koha::Account::Lines->find( { accountlines_id => $line->accountlines_id } ); + is( $updated_line->amountoutstanding + 0, 0, "Line amount outstanding is 0" ); + is( $updated_line->status, 'FOUND', "Line has been struck off as 'FOUND'" ); + + my $credit = + Koha::Account::Lines->find( { borrowernumber => $patron->borrowernumber, credit_type_code => 'LOST_FOUND' } ); + is( $credit->amount + 0, -10, "Credit amount is 10" ); + is( $credit->description, "Item found $itemnumber", "Credit has been marked as relating to the item being found" ); +}; + subtest 'Test Koha::Checkout::claim_returned should not update the itemlost status if it is already set' => sub { plan tests => 2; diff --git a/t/db_dependent/api/v1/return_claims.t b/t/db_dependent/api/v1/return_claims.t index a79dd9e73f..a151cee26d 100755 --- a/t/db_dependent/api/v1/return_claims.t +++ b/t/db_dependent/api/v1/return_claims.t @@ -72,6 +72,7 @@ subtest 'claim_returned() tests' => sub { "//$userid:$password@/api/v1/return_claims" => json => { item_id => $item->itemnumber, charge_lost_fee => Mojo::JSON->false, + refund_lost_fee => Mojo::JSON->false, created_by => $librarian->id, notes => "This is a test note." } @@ -88,6 +89,7 @@ subtest 'claim_returned() tests' => sub { "//$userid:$password@/api/v1/return_claims" => json => { item_id => $item->itemnumber, charge_lost_fee => Mojo::JSON->false, + refund_lost_fee => Mojo::JSON->false, created_by => $librarian->id, notes => "This is a test note." } @@ -101,6 +103,7 @@ subtest 'claim_returned() tests' => sub { "//$userid:$password@/api/v1/return_claims" => json => { item_id => $item->itemnumber, charge_lost_fee => Mojo::JSON->false, + refund_lost_fee => Mojo::JSON->false, created_by => $librarian->id, notes => "This is a test note." } -- 2.39.5