Bugzilla – Attachment 122179 Details for
Bug 28588
Add Koha::Checkouts::ReturnClaim->resolve
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28588: Unit tests
Bug-28588-Unit-tests.patch (text/plain), 4.89 KB, created by
David Nind
on 2021-06-18 20:16:16 UTC
(
hide
)
Description:
Bug 28588: Unit tests
Filename:
MIME Type:
Creator:
David Nind
Created:
2021-06-18 20:16:16 UTC
Size:
4.89 KB
patch
obsolete
>From 8cfbbd60e5611565f83d15a58241b0d8f2cdfab1 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 18 Jun 2021 16:14:43 -0300 >Subject: [PATCH] Bug 28588: Unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: David Nind <david@davidnind.com> >--- > t/db_dependent/Koha/Checkouts/ReturnClaim.t | 123 +++++++++++++++++++- > 1 file changed, 122 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Checkouts/ReturnClaim.t b/t/db_dependent/Koha/Checkouts/ReturnClaim.t >index cb31b10f1c..f614895f89 100755 >--- a/t/db_dependent/Koha/Checkouts/ReturnClaim.t >+++ b/t/db_dependent/Koha/Checkouts/ReturnClaim.t >@@ -17,10 +17,11 @@ > > use Modern::Perl; > >-use Test::More tests => 1; >+use Test::More tests => 2; > use Test::Exception; > > use Koha::Database; >+use Koha::DateUtils qw( dt_from_string output_pref ); > use Koha::Checkouts::ReturnClaims; > > use t::lib::TestBuilder; >@@ -148,3 +149,123 @@ subtest "store() tests" => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest "resolve() tests" => sub { >+ >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ my $itemlost = 1; >+ my $librarian = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $item = $builder->build_sample_item({ itemlost => $itemlost }); >+ >+ my $checkout = $builder->build_object( >+ { >+ class => 'Koha::Checkouts', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ itemnumber => $item->itemnumber, >+ branchcode => $patron->branchcode >+ } >+ } >+ ); >+ >+ my $claim = Koha::Checkouts::ReturnClaim->new( >+ { >+ issue_id => $checkout->id, >+ itemnumber => $checkout->itemnumber, >+ borrowernumber => $checkout->borrowernumber, >+ notes => 'Some notes', >+ created_by => $librarian->borrowernumber >+ } >+ )->store; >+ >+ throws_ok >+ { $claim->resolve({ resolution => 1 }); } >+ 'Koha::Exceptions::MissingParameter', >+ "Not passing 'resolved_by' makes it throw an exception"; >+ >+ throws_ok >+ { $claim->resolve({ resolved_by => 1 }); } >+ 'Koha::Exceptions::MissingParameter', >+ "Not passing 'resolution' makes it throw an exception"; >+ >+ my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $deleted_patron_id = $deleted_patron->id; >+ $deleted_patron->delete; >+ >+ { # hide useless warnings >+ local *STDERR; >+ open STDERR, '>', '/dev/null'; >+ >+ throws_ok >+ { $claim->resolve({ resolution => "X", resolved_by => $deleted_patron_id }) } >+ 'Koha::Exceptions::Object::FKConstraint', >+ "Exception thrown on invalid resolver"; >+ >+ close STDERR; >+ } >+ >+ my $today = dt_from_string; >+ my $tomorrow = dt_from_string->add( days => 1 ); >+ >+ $claim->resolve( >+ { >+ resolution => "X", >+ resolved_by => $librarian->id, >+ resolved_on => $tomorrow, >+ } >+ )->discard_changes; >+ >+ is( output_pref( { str => $claim->resolved_on } ), output_pref( { dt => $tomorrow } ), 'resolved_on set to the passed param' ); >+ is( $claim->updated_by, $librarian->id, 'updated_by set to the passed resolved_by' ); >+ >+ # Make sure $item is refreshed >+ $item->discard_changes; >+ is( $item->itemlost, $itemlost, 'Item lost status remains unchanged' ); >+ >+ # New checkout and claim >+ $checkout->delete; >+ $checkout = $builder->build_object( >+ { >+ class => 'Koha::Checkouts', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ itemnumber => $item->itemnumber, >+ branchcode => $patron->branchcode >+ } >+ } >+ ); >+ >+ $claim = Koha::Checkouts::ReturnClaim->new( >+ { >+ issue_id => $checkout->id, >+ itemnumber => $checkout->itemnumber, >+ borrowernumber => $checkout->borrowernumber, >+ notes => 'Some notes', >+ created_by => $librarian->borrowernumber >+ } >+ )->store; >+ >+ my $new_lost_status = 2; >+ >+ $claim->resolve( >+ { >+ resolution => "X", >+ resolved_by => $librarian->id, >+ resolved_on => $tomorrow, >+ new_lost_status => $new_lost_status, >+ } >+ )->discard_changes; >+ >+ is( output_pref( { str => $claim->resolved_on } ), output_pref( { dt => $tomorrow } ), 'resolved_on set to the passed param' ); >+ is( $claim->updated_by, $librarian->id, 'updated_by set to the passed resolved_by' ); >+ >+ # Make sure $item is refreshed >+ $item->discard_changes; >+ is( $item->itemlost, $new_lost_status, 'Item lost status is updated' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28588
:
122174
|
122175
|
122176
|
122179
|
122180
|
122181
|
122219
|
122220
|
122221