From 31eba0e77952fc3c15b82772f92190f4650cc7e8 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 5 Oct 2021 11:10:10 -0300 Subject: [PATCH] Bug 27947: (QA follow-up) Make parameters a hashref This patch makes the Koha::ArticleRequest->cancel parameters into a hashref. (Missing) tests are added for those parameters being set as well. Calls to ->cancel are updated. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/ArticleRequest.t \ t/db_dependent/api/v1/article_requests.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/ArticleRequest.pm | 5 ++++- Koha/REST/V1/ArticleRequests.pm | 18 ++++++++++++++---- svc/article_request | 2 +- t/db_dependent/Koha/ArticleRequest.t | 9 +++++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm index 5d036a0283..e03af23173 100644 --- a/Koha/ArticleRequest.pm +++ b/Koha/ArticleRequest.pm @@ -122,7 +122,10 @@ Marks the article as cancelled. Send a notification if appropriate. =cut sub cancel { - my ( $self, $cancellation_reason, $notes ) = @_; + my ( $self, $params ) = @_; + + my $cancellation_reason = $params->{cancellation_reason}; + my $notes = $params->{notes}; $self->status(Koha::ArticleRequest::Status::Canceled); $self->cancellation_reason($cancellation_reason) if $cancellation_reason; diff --git a/Koha/REST/V1/ArticleRequests.pm b/Koha/REST/V1/ArticleRequests.pm index 58e3f4bfef..af6884174e 100644 --- a/Koha/REST/V1/ArticleRequests.pm +++ b/Koha/REST/V1/ArticleRequests.pm @@ -52,11 +52,16 @@ sub cancel { } my $reason = $c->validation->param('cancellation_reason'); - my $notes = $c->validation->param('notes'); + my $notes = $c->validation->param('notes'); return try { - $article_request->cancel($reason, $notes); + $article_request->cancel( + { + cancellation_reason => $reason, + notes => $notes + } + ); return $c->render( status => 204, openapi => q{} @@ -96,11 +101,16 @@ sub patron_cancel { } my $reason = $c->validation->param('cancellation_reason'); - my $notes = $c->validation->param('notes'); + my $notes = $c->validation->param('notes'); return try { - $article_request->cancel( $reason, $notes ); + $article_request->cancel( + { + cancellation_reason => $reason, + notes => $notes + } + ); return $c->render( status => 204, openapi => q{} diff --git a/svc/article_request b/svc/article_request index 3b5105ad0d..e8c8e7f819 100755 --- a/svc/article_request +++ b/svc/article_request @@ -45,7 +45,7 @@ my $ar = Koha::ArticleRequests->find($id); if ($ar) { if ( $action eq 'cancel' ) { - $ar = $ar->cancel( $notes ); + $ar = $ar->cancel({ notes => $notes }); } elsif ( $action eq 'process' ) { $ar = $ar->process(); diff --git a/t/db_dependent/Koha/ArticleRequest.t b/t/db_dependent/Koha/ArticleRequest.t index e4caffbdfd..2f851f3c1c 100755 --- a/t/db_dependent/Koha/ArticleRequest.t +++ b/t/db_dependent/Koha/ArticleRequest.t @@ -116,7 +116,7 @@ subtest 'complete() tests' => sub { subtest 'cancel() tests' => sub { - plan tests => 2; + plan tests => 4; $schema->storage->txn_begin; @@ -129,9 +129,14 @@ subtest 'cancel() tests' => sub { } ); - $ar->cancel()->discard_changes; + my $reason = "Hey, ho"; + my $notes = "Let's go!"; + + $ar->cancel({ cancellation_reason => $reason, notes => $notes })->discard_changes; is( $ar->status, Koha::ArticleRequest::Status::Canceled ); + is( $ar->cancellation_reason, $reason, 'Cancellation reason stored correctly' ); + is( $ar->notes, $notes, 'Notes stored correctly' ); $schema->storage->txn_rollback; }; -- 2.32.0