Bugzilla – Attachment 183108 Details for
Bug 39657
Block holds placed via the API when patron would be blocked from placing OPAC hold
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39657: Unit tests
Bug-39657-Unit-tests.patch (text/plain), 3.38 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-06-09 22:51:32 UTC
(
hide
)
Description:
Bug 39657: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-06-09 22:51:32 UTC
Size:
3.38 KB
patch
obsolete
>From de8a0b79bf87a2beb7c637f659eb9a17d9233479 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 9 Jun 2025 19:41:20 -0300 >Subject: [PATCH] Bug 39657: Unit tests > >--- > t/db_dependent/api/v1/holds.t | 70 +++++++++++++++++++++++++++++++++-- > 1 file changed, 67 insertions(+), 3 deletions(-) > >diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t >index a07374d751a..dd31a455ab9 100755 >--- a/t/db_dependent/api/v1/holds.t >+++ b/t/db_dependent/api/v1/holds.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 15; >+use Test::More tests => 16; > use Test::MockModule; > use Test::Mojo; > use t::lib::TestBuilder; >@@ -697,8 +697,12 @@ subtest 'add() tests (maxreserves behaviour)' => sub { > item_id => $item_3->itemnumber > }; > >- $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )->status_is(403) >- ->json_is( { error => 'Hold cannot be placed. Reason: tooManyReserves' } ); >+ $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )->status_is(409)->json_is( >+ { >+ error => 'Hold cannot be placed. Reason: hold_limit', >+ error_code => 'hold_limit' >+ } >+ ); > > t::lib::Mocks::mock_preference( 'maxreserves', 0 ); > >@@ -717,6 +721,66 @@ subtest 'add() tests (maxreserves behaviour)' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'add() + can_place_holds() tests' => sub { >+ >+ plan tests => 30; >+ >+ $schema->storage->txn_begin; >+ >+ my $password = 'AbcdEFG123'; >+ >+ my $library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); >+ my $patron = >+ $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library->id, flags => 1 } } ); >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $patron->userid; >+ >+ my $current_message; >+ my $patron_mock = Test::MockModule->new('Koha::Patron'); >+ >+ $patron_mock->mock( >+ 'can_place_holds', >+ sub { >+ return Koha::Result::Boolean->new(0)->add_message( { type => 'error', message => $current_message } ); >+ } >+ ); >+ >+ my $item = $builder->build_sample_item( { library => $library->id } ); >+ >+ my @messages = qw( >+ expired >+ debt_limit >+ bad_address >+ card_lost >+ restricted >+ hold_limit); >+ >+ foreach my $message (@messages) { >+ >+ $current_message = $message; >+ >+ my $post_data = { >+ patron_id => $patron->id, >+ biblio_id => $item->biblio->id, >+ pickup_library_id => $item->holdingbranch, >+ item_id => $item->id >+ }; >+ >+ $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data ) >+ ->status_is( 409, "Expected error related to '$message'" ) >+ ->json_is( { error => "Hold cannot be placed. Reason: $message", error_code => $message } ); >+ >+ my $hold_id = >+ $t->post_ok( >+ "//$userid:$password@/api/v1/holds" => { 'x-koha-override' => $message } => json => $post_data ) >+ ->status_is( 201, "Override works for '$message'" )->tx->res->json->{hold_id}; >+ >+ Koha::Holds->find($hold_id)->delete(); >+ } >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'pickup_locations() tests' => sub { > > plan tests => 15; >-- >2.49.0
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 39657
:
183108
|
183109
|
183110
|
183200
|
183201
|
183202
|
183491
|
183492
|
183493