Bugzilla – Attachment 84375 Details for
Bug 20006
Adapt /v1/holds to new naming guidelines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20006: Unit tests fixes
Bug-20006-Unit-tests-fixes.patch (text/plain), 10.09 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-01-24 17:57:43 UTC
(
hide
)
Description:
Bug 20006: Unit tests fixes
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-01-24 17:57:43 UTC
Size:
10.09 KB
patch
obsolete
>From d23b6e1d7b5b9836eb3c2ad19457eeaf877f0032 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 24 Jan 2019 14:51:03 -0300 >Subject: [PATCH] Bug 20006: Unit tests fixes > >This patch makes the holds endpoint tests pass and expect data structures that match the voted RFC. > >As we voted to introduce a /public namespace for unprivileged access to >endpoints, this endpoint gets the ability for owners and guarantors to >manipulate holds through the API. >--- > t/db_dependent/api/v1/holds.t | 120 +++++++++++----------------------- > 1 file changed, 38 insertions(+), 82 deletions(-) > >diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t >index 1e00be1a3b..fd8987ade7 100644 >--- 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 => 5; >+use Test::More tests => 4; > use Test::Mojo; > use t::lib::TestBuilder; > use t::lib::Mocks; >@@ -149,19 +149,20 @@ my $reserve_id = C4::Reserves::AddReserve($branchcode, $patron_1->borrowernumber > my $reserve_id2 = C4::Reserves::AddReserve($branchcode, $patron_2->borrowernumber, > $biblionumber, undef, 2, undef, undef, undef, '', $itemnumber); > >-my $suspend_until = DateTime->now->add(days => 10)->ymd; >-my $expirationdate = DateTime->now->add(days => 10)->ymd; >+my $suspended_until = DateTime->now->add(days => 10)->truncate( to => 'day' ); >+my $expiration_date = DateTime->now->add(days => 10)->truncate( to => 'day' ); > > my $post_data = { >- borrowernumber => int($patron_1->borrowernumber), >- biblionumber => int($biblionumber), >- itemnumber => int($itemnumber), >- branchcode => $branchcode, >- expirationdate => $expirationdate, >+ patron_id => int($patron_1->borrowernumber), >+ biblio_id => int($biblionumber), >+ item_id => int($itemnumber), >+ pickup_library_id => $branchcode, >+ expiration_date => output_pref({ dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 }), >+ priority => 2, > }; > my $put_data = { > priority => 2, >- suspend_until => $suspend_until, >+ suspended_until => output_pref({ dt => $suspended_until, dateformat => 'rfc3339' }), > }; > > subtest "Test endpoints without authentication" => sub { >@@ -180,11 +181,11 @@ subtest "Test endpoints without authentication" => sub { > subtest "Test endpoints without permission" => sub { > plan tests => 10; > >- $tx = $t->ua->build_tx(GET => "/api/v1/holds?borrowernumber=" . $patron_1->borrowernumber); >+ $tx = $t->ua->build_tx(GET => "/api/v1/holds?patron_id=" . $patron_1->borrowernumber); > $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); > $t->request_ok($tx) # no permission > ->status_is(403); >- $tx = $t->ua->build_tx(GET => "/api/v1/holds?borrowernumber=" . $patron_1->borrowernumber); >+ $tx = $t->ua->build_tx(GET => "/api/v1/holds?patron_id=" . $patron_1->borrowernumber); > $tx->req->cookies({name => 'CGISESSID', value => $session3->id}); > $t->request_ok($tx) # reserveforothers permission > ->status_is(403); >@@ -201,47 +202,10 @@ subtest "Test endpoints without permission" => sub { > $t->request_ok($tx) # no permission > ->status_is(403); > }; >-subtest "Test endpoints without permission, but accessing own object" => sub { >- plan tests => 16; >- >- my $borrno_tmp = $post_data->{'borrowernumber'}; >- $post_data->{'borrowernumber'} = int $nopermission->{'borrowernumber'}; >- $tx = $t->ua->build_tx(POST => "/api/v1/holds" => json => $post_data); >- $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); >- $t->request_ok($tx) # create hold to myself >- ->status_is(201) >- ->json_has('/reserve_id'); >- >- $post_data->{'borrowernumber'} = $borrno_tmp; >- $tx = $t->ua->build_tx(GET => "/api/v1/holds?borrowernumber=".$nopermission-> { borrowernumber }); >- $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); >- $t->request_ok($tx) # get my own holds >- ->status_is(200) >- ->json_is('/0/borrowernumber', $nopermission->{ borrowernumber }) >- ->json_is('/0/biblionumber', $biblionumber) >- ->json_is('/0/itemnumber', $itemnumber) >- ->json_is('/0/expirationdate', $expirationdate) >- ->json_is('/0/branchcode', $branchcode); >- >- my $reserve_id3 = Koha::Holds->find({ borrowernumber => $nopermission->{borrowernumber} })->reserve_id; >- $tx = $t->ua->build_tx(PUT => "/api/v1/holds/$reserve_id3" => json => $put_data); >- $tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); >- $t->request_ok($tx) # create hold to myself >- ->status_is(200)->json_is( '/reserve_id', $reserve_id3 )->json_is( >- '/suspend_until', >- output_pref( >- { >- dateformat => 'rfc3339', >- dt => dt_from_string( $suspend_until . ' 00:00:00', 'sql' ) >- } >- ) >- ) >- ->json_is( '/priority', 2 ) >- ->json_is( '/itemnumber', $itemnumber ); >-}; > > subtest "Test endpoints with permission" => sub { >- plan tests => 45; >+ >+ plan tests => 44; > > $tx = $t->ua->build_tx(GET => '/api/v1/holds'); > $tx->req->cookies({name => 'CGISESSID', value => $session->id}); >@@ -249,28 +213,21 @@ subtest "Test endpoints with permission" => sub { > ->status_is(200) > ->json_has('/0') > ->json_has('/1') >- ->json_has('/2') >- ->json_hasnt('/3'); >+ ->json_hasnt('/2'); > > $tx = $t->ua->build_tx(GET => '/api/v1/holds?priority=2'); > $tx->req->cookies({name => 'CGISESSID', value => $session->id}); > $t->request_ok($tx) > ->status_is(200) >- ->json_is('/0/borrowernumber', $nopermission->{borrowernumber}) >+ ->json_is('/0/patron_id', $patron_2->borrowernumber) > ->json_hasnt('/1'); > > $tx = $t->ua->build_tx(PUT => "/api/v1/holds/$reserve_id" => json => $put_data); > $tx->req->cookies({name => 'CGISESSID', value => $session3->id}); >- $t->request_ok($tx)->status_is(200)->json_is( '/reserve_id', $reserve_id ) >- ->json_is( >- '/suspend_until', >- output_pref( >- { >- dateformat => 'rfc3339', >- dt => dt_from_string( $suspend_until . ' 00:00:00', 'sql' ) >- } >- ) >- ) >+ $t->request_ok($tx) >+ ->status_is(200) >+ ->json_is( '/hold_id', $reserve_id ) >+ ->json_is( '/suspended_until', output_pref({ dt => $suspended_until, dateformat => 'rfc3339' }) ) > ->json_is( '/priority', 2 ); > > $tx = $t->ua->build_tx(DELETE => "/api/v1/holds/$reserve_id"); >@@ -290,14 +247,14 @@ subtest "Test endpoints with permission" => sub { > ->status_is(404) > ->json_has('/error'); > >- $tx = $t->ua->build_tx(GET => "/api/v1/holds?borrowernumber=" . $patron_1->borrowernumber); >+ $tx = $t->ua->build_tx(GET => "/api/v1/holds?patron_id=" . $patron_1->borrowernumber); > $tx->req->cookies({name => 'CGISESSID', value => $session2->id}); # get with borrowers flag > $t->request_ok($tx) > ->status_is(200) > ->json_is([]); > > my $inexisting_borrowernumber = $patron_2->borrowernumber * 2; >- $tx = $t->ua->build_tx(GET => "/api/v1/holds?borrowernumber=$inexisting_borrowernumber"); >+ $tx = $t->ua->build_tx(GET => "/api/v1/holds?patron_id=$inexisting_borrowernumber"); > $tx->req->cookies({name => 'CGISESSID', value => $session->id}); > $t->request_ok($tx) > ->status_is(200) >@@ -312,16 +269,16 @@ subtest "Test endpoints with permission" => sub { > $tx->req->cookies({name => 'CGISESSID', value => $session3->id}); > $t->request_ok($tx) > ->status_is(201) >- ->json_has('/reserve_id'); >- $reserve_id = $t->tx->res->json->{reserve_id}; >+ ->json_has('/hold_id'); >+ $reserve_id = $t->tx->res->json->{hold_id}; > >- $tx = $t->ua->build_tx(GET => "/api/v1/holds?borrowernumber=" . $patron_1->borrowernumber); >+ $tx = $t->ua->build_tx(GET => "/api/v1/holds?patron_id=" . $patron_1->borrowernumber); > $tx->req->cookies({name => 'CGISESSID', value => $session->id}); > $t->request_ok($tx) > ->status_is(200) >- ->json_is('/0/reserve_id', $reserve_id) >- ->json_is('/0/expirationdate', $expirationdate) >- ->json_is('/0/branchcode', $branchcode); >+ ->json_is('/0/hold_id', $reserve_id) >+ ->json_is('/0/expiration_date', output_pref({ dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 })) >+ ->json_is('/0/pickup_library_id', $branchcode); > > $tx = $t->ua->build_tx(POST => "/api/v1/holds" => json => $post_data); > $tx->req->cookies({name => 'CGISESSID', value => $session3->id}); >@@ -335,18 +292,17 @@ subtest "Test endpoints with permission" => sub { > $tx->req->cookies({name => 'CGISESSID', value => $session3->id}); > $t->request_ok($tx) > ->status_is(403) >- ->json_like('/error', qr/tooManyReserves/); >+ ->json_like('/error', qr/itemAlreadyOnHold/); > }; > >- > subtest 'Reserves with itemtype' => sub { > plan tests => 9; > > my $post_data = { >- borrowernumber => int($patron_1->borrowernumber), >- biblionumber => int($biblionumber), >- branchcode => $branchcode, >- itemtype => $itemtype, >+ patron_id => int($patron_1->borrowernumber), >+ biblio_id => int($biblionumber), >+ pickup_library_id => $branchcode, >+ item_type => $itemtype, > }; > > $tx = $t->ua->build_tx(DELETE => "/api/v1/holds/$reserve_id"); >@@ -358,16 +314,16 @@ subtest 'Reserves with itemtype' => sub { > $tx->req->cookies({name => 'CGISESSID', value => $session3->id}); > $t->request_ok($tx) > ->status_is(201) >- ->json_has('/reserve_id'); >+ ->json_has('/hold_id'); > >- $reserve_id = $t->tx->res->json->{reserve_id}; >+ $reserve_id = $t->tx->res->json->{hold_id}; > >- $tx = $t->ua->build_tx(GET => "/api/v1/holds?borrowernumber=" . $patron_1->borrowernumber); >+ $tx = $t->ua->build_tx(GET => "/api/v1/holds?patron_id=" . $patron_1->borrowernumber); > $tx->req->cookies({name => 'CGISESSID', value => $session->id}); > $t->request_ok($tx) > ->status_is(200) >- ->json_is('/0/reserve_id', $reserve_id) >- ->json_is('/0/itemtype', $itemtype); >+ ->json_is('/0/hold_id', $reserve_id) >+ ->json_is('/0/item_type', $itemtype); > }; > > $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 20006
:
84374
|
84375
|
84376
|
84381
|
84382
|
84386
|
84395
|
84396
|
84397
|
84398
|
84399
|
85051
|
85052
|
85053
|
85054
|
85055
|
85856
|
85857
|
85858
|
85859
|
85860