Bugzilla – Attachment 119715 Details for
Bug 27932
Add GET /biblios/:biblio_id/pickup_locations
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27932: Unit tests
Bug-27932-Unit-tests.patch (text/plain), 5.12 KB, created by
Martin Renvoize (ashimema)
on 2021-04-16 12:04:56 UTC
(
hide
)
Description:
Bug 27932: Unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-04-16 12:04:56 UTC
Size:
5.12 KB
patch
obsolete
>From 94541a161198d11a9b13ae97219d1f2fa5a0d83c Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 11 Mar 2021 15:46:57 -0300 >Subject: [PATCH] Bug 27932: Unit tests > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/api/v1/biblios.t | 120 +++++++++++++++++++++++++++++++- > 1 file changed, 119 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t >index fa75ff4dd4..006d8f2da3 100755 >--- a/t/db_dependent/api/v1/biblios.t >+++ b/t/db_dependent/api/v1/biblios.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 5; > use Test::MockModule; > use Test::Mojo; > use Test::Warn; >@@ -329,3 +329,121 @@ subtest 'get_public() 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 $biblio_class = Test::MockModule->new('Koha::Biblio'); >+ $biblio_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' } >+ } >+ ); >+ } >+ ); >+ >+ my $biblio = $builder->build_sample_biblio; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/biblios/" >+ . $biblio->id >+ . "/pickup_locations?patron_id=" . $patron->id ) >+ ->json_is( [ $library_1_api, $library_2_api ] ); >+ >+ # filtering works! >+ $t->get_ok( "//$userid:$password@/api/v1/biblios/" >+ . $biblio->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/biblios/" >+ . $biblio->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/biblios/" >+ . $biblio->id >+ . "/pickup_locations?" >+ . "patron_id=" . $deleted_patron_id ) >+ ->status_is( 400 ) >+ ->json_is( '/error' => 'Patron not found' ); >+ >+ $biblio->delete; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/biblios/" >+ . $biblio->id >+ . "/pickup_locations?" >+ . "patron_id=" . $patron->id ) >+ ->status_is( 404 ) >+ ->json_is( '/error' => 'Biblio 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 27932
:
118168
|
118169
|
118172
|
118173
|
118216
| 119715 |
119716