Bugzilla – Attachment 119719 Details for
Bug 27931
Add GET /items/:item_id/pickup_locations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27931: Unit tests
Bug-27931-Unit-tests.patch (text/plain), 5.05 KB, created by
Martin Renvoize (ashimema)
on 2021-04-16 12:10:06 UTC
(
hide
)
Description:
Bug 27931: Unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-04-16 12:10:06 UTC
Size:
5.05 KB
patch
obsolete
>From fb0b93c73956f1818c2a28def47483be4989e100 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 11 Mar 2021 16:30:18 -0300 >Subject: [PATCH] Bug 27931: Unit tests > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/api/v1/items.t | 120 +++++++++++++++++++++++++++++++++- > 1 file changed, 119 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/items.t b/t/db_dependent/api/v1/items.t >index a3ba781cf4..4136c28a08 100755 >--- a/t/db_dependent/api/v1/items.t >+++ b/t/db_dependent/api/v1/items.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; > use Test::Mojo; > use Test::Warn; > >@@ -141,3 +141,121 @@ subtest 'get() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'pickup_locations() tests' => sub { >+ >+ plan tests => 15; >+ >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 ); >+ >+ # Small trick to ease testing >+ Koha::Libraries->search->update({ pickup_location => 0 }); >+ >+ my $library_1 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'A', pickup_location => 1 } }); >+ my $library_2 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'B', pickup_location => 1 } }); >+ my $library_3 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'C', pickup_location => 1 } }); >+ >+ my $library_1_api = $library_1->to_api(); >+ my $library_2_api = $library_2->to_api(); >+ my $library_3_api = $library_3->to_api(); >+ >+ $library_1_api->{needs_override} = Mojo::JSON->false; >+ $library_2_api->{needs_override} = Mojo::JSON->false; >+ $library_3_api->{needs_override} = Mojo::JSON->true; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { userid => 'tomasito', flags => 0 } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $patron->userid; >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ module_bit => 6, >+ code => 'place_holds', >+ }, >+ } >+ ); >+ >+ my $item = $builder->build_sample_item(); >+ >+ my $item_class = Test::MockModule->new('Koha::Item'); >+ $item_class->mock( >+ 'pickup_locations', >+ sub { >+ my ( $self, $params ) = @_; >+ my $mock_patron = $params->{patron}; >+ is( $mock_patron->borrowernumber, >+ $patron->borrowernumber, 'Patron passed correctly' ); >+ return Koha::Libraries->search( >+ { >+ branchcode => { >+ '-in' => [ >+ $library_1->branchcode, >+ $library_2->branchcode >+ ] >+ } >+ }, >+ { # we make sure no surprises in the order of the result >+ order_by => { '-asc' => 'marcorgcode' } >+ } >+ ); >+ } >+ ); >+ >+ $t->get_ok( "//$userid:$password@/api/v1/items/" >+ . $item->id >+ . "/pickup_locations?patron_id=" . $patron->id ) >+ ->json_is( [ $library_1_api, $library_2_api ] ); >+ >+ # filtering works! >+ $t->get_ok( "//$userid:$password@/api/v1/items/" >+ . $item->id >+ . '/pickup_locations?' >+ . 'patron_id=' . $patron->id . '&q={"marc_org_code": { "-like": "A%" }}' ) >+ ->json_is( [ $library_1_api ] ); >+ >+ t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 ); >+ >+ my $library_4 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 0, marcorgcode => 'X' } }); >+ my $library_5 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1, marcorgcode => 'Y' } }); >+ >+ my $library_5_api = $library_5->to_api(); >+ $library_5_api->{needs_override} = Mojo::JSON->true; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/items/" >+ . $item->id >+ . "/pickup_locations?" >+ . "patron_id=" . $patron->id . "&_order_by=marc_org_code" ) >+ ->json_is( [ $library_1_api, $library_2_api, $library_3_api, $library_5_api ] ); >+ >+ my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $deleted_patron_id = $deleted_patron->id; >+ $deleted_patron->delete; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/items/" >+ . $item->id >+ . "/pickup_locations?" >+ . "patron_id=" . $deleted_patron_id ) >+ ->status_is( 400 ) >+ ->json_is( '/error' => 'Patron not found' ); >+ >+ $item->delete; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/items/" >+ . $item->id >+ . "/pickup_locations?" >+ . "patron_id=" . $patron->id ) >+ ->status_is( 404 ) >+ ->json_is( '/error' => 'Item not found' ); >+ >+ $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 27931
:
118170
|
118171
| 119719 |
119720