From 180338f62fb79ea2c8e8ea57ca2aa36c94604105 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 This patch fixes the tests so they highlight the fact that: - PUT only worked on the tests because borrowernumber was passed on them - ModMember expects borrowernumber on the hash it gets passed. It also fixes the issue. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/api/v1/patrons.t => SUCCESS: Tests pass Signed-off-by: Tomas Cohen Arazi Signed-off-by: Benjamin Rokseth --- 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 357c099..7868e8d 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 e850259..b52066d 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.1.4