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 <kkrueger@cuyahogalibrary.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Matt Blenkinsop 2024-09-26 13:00:26 +00:00 committed by Katrin Fischer
parent 432e32e368
commit 4b37f32c87
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 44 additions and 1 deletions

View File

@ -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;

View File

@ -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."
}