From e36dc18376390d2747ce5d831064146817cd24c9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 12 Dec 2017 18:53:45 -0300 Subject: [PATCH] Bug 16330: (QA follow-up) ModMember requires borrowernumber MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Works perfectly. Well done everyone! Signed-off-by: Tomas Cohen Arazi Signed-off-by: Benjamin Rokseth Signed-off-by: Dilan Johnpullé Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- Koha/REST/V1/Patrons.pm | 5 ++++- t/db_dependent/api/v1/patrons.t | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm index 357c0991cf..7868e8d148 100644 --- a/Koha/REST/V1/Patrons.pm +++ b/Koha/REST/V1/Patrons.pm @@ -154,7 +154,10 @@ sub update { $patron->set( _to_model($body) )->_validate; - # TODO: Use ModMember until it has been moved to Koha-namespace + ## TODO: Use ModMember until it has been moved to Koha-namespace + # Add borrowernumber to $body, as required by ModMember + $body->{borrowernumber} = $patron->borrowernumber; + if ( ModMember(%$body) ) { return $c->render( status => 200, openapi => $patron ); } diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 26e241bf8c..a23b47be10 100644 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -231,6 +231,8 @@ subtest 'update() tests' => sub { my $patron_1 = Koha::Patrons->find($borrowernumber); my $patron_2 = Koha::Patrons->find($borrowernumber2); my $newpatron = $patron_2->TO_JSON; + # borrowernumber should not be passed in the request body for PUT + delete $newpatron->{borrowernumber}; my $tx = $t->ua->build_tx(PUT => "/api/v1/patrons/-1" => json => $newpatron ); $tx->req->cookies({name => 'CGISESSID', value => $sessionid}); @@ -282,13 +284,12 @@ subtest 'update() tests' => sub { $newpatron->{ userid } = "user".$borrowernumber.$borrowernumber2; $newpatron->{ surname } = "user".$borrowernumber.$borrowernumber2; - $tx = $t->ua->build_tx(PUT => "/api/v1/patrons/" . - $newpatron->{borrowernumber} => json => $newpatron); + $tx = $t->ua->build_tx(PUT => "/api/v1/patrons/" . $patron_2->id => json => $newpatron); $tx->req->cookies({name => 'CGISESSID', value => $sessionid}); $t->request_ok($tx) ->status_is(200, 'Patron updated successfully') ->json_has($newpatron); - is(Koha::Patrons->find($newpatron->{borrowernumber})->cardnumber, + is(Koha::Patrons->find( $patron_2->id )->cardnumber, $newpatron->{ cardnumber }, 'Patron is really updated!'); }; -- 2.39.5