From c2ee8de558a5a1f2d9f30a0d7d95bc38c13ea952 Mon Sep 17 00:00:00 2001
From: Arthur Suzuki <arthur.suzuki@biblibre.com>
Date: Thu, 20 Apr 2023 12:25:22 +0000
Subject: [PATCH] hotline#177286 : add explicit message for
 BorrowerCannotCancelHold error message

---
 VERSIONS_HOTLINE/177286                         |  1 +
 library/Class/WebService/SIGB/Koha/Service.php  | 17 +++++++++--------
 .../library/Class/WebService/SIGB/KohaTest.php  | 16 +++++++++++++++-
 3 files changed, 25 insertions(+), 9 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/177286

diff --git a/VERSIONS_HOTLINE/177286 b/VERSIONS_HOTLINE/177286
new file mode 100644
index 00000000000..25fcc28a017
--- /dev/null
+++ b/VERSIONS_HOTLINE/177286
@@ -0,0 +1 @@
+ - correctif #177286 : SIGB Koha : Ajout d'un message plus explicite en cas d'impossibilité d'annuler une réservation
\ No newline at end of file
diff --git a/library/Class/WebService/SIGB/Koha/Service.php b/library/Class/WebService/SIGB/Koha/Service.php
index 848ca19a9ab..64a6a84a9e8 100644
--- a/library/Class/WebService/SIGB/Koha/Service.php
+++ b/library/Class/WebService/SIGB/Koha/Service.php
@@ -77,6 +77,8 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
                        'tooManyReservesToday' => $this->_('vous avez atteint votre quota journalier de réservation pour ce type de documents'),
                        'none_available' => $this->_('aucun document n\'est disponible pour la réservation'),
                        'on_reserve' => $this->_('document réservé par un autre lecteur'),
+                       'BorrowerCannotCancelHold' => $this->_('Cette réservation ne peut être annulée'),
+                       'Canceled' => $this->_('Réservation annulée'),
                        'too_many' => $this->_('nombre maximum de prolongations atteint'),
                        'onsite_checkout' => $this->_('document en prêt sur place'),
                        'restriction' => $this->_('compte bloqué'),
@@ -386,15 +388,14 @@ class Class_WebService_SIGB_Koha_Service extends Class_WebService_SIGB_AbstractR
    * @return array
    */
   public function supprimerReservation($user, $reservation_id) {
-    $xml_cancel = $this->httpGet(array('service' => 'CancelHold',
-                                       'patron_id' => $user->getIdSigb(),
-                                       'item_id' => $reservation_id));
-
-    $code = $this->_getTagData($xml_cancel, 'code');
-
-    return ($code == 'Canceled')
+    $response = $this->ilsdiAction('CancelHold',
+                               ['patron_id' => $user->getIdSigb(),
+                                'item_id' => $reservation_id],
+                               'code',
+                               $this->_('Annulation impossible'));
+    return strpos($response['erreur'], $this->_('Réservation annulée'))
       ? $this->_success()
-      : $this->_error($code);
+      : $response;
   }
 
 
diff --git a/tests/library/Class/WebService/SIGB/KohaTest.php b/tests/library/Class/WebService/SIGB/KohaTest.php
index cf3499e5c3d..87b2231ccc9 100644
--- a/tests/library/Class/WebService/SIGB/KohaTest.php
+++ b/tests/library/Class/WebService/SIGB/KohaTest.php
@@ -1390,7 +1390,21 @@ class KohaOperationsTest extends KohaTestCase {
       ->answers('<CancelHold><code>NotCanceled</code></CancelHold>');
 
 
-    $this->assertEquals(['statut' => false,'erreur' => 'NotCanceled'],
+    $this->assertEquals(['statut' => false,'erreur' => 'Annulation impossible'],
+                        $this->service->supprimerReservation($this->_lafond, '24426'));
+  }
+
+
+  /** @test */
+  function supprimerReservationShouldReturnErrorFromCode() {
+    $this->mock_web_client
+      ->whenCalled('open_url')
+      ->with('http://cat-aficg55.biblibre.com/cgi-bin/koha/ilsdi.pl?service=CancelHold&patron_id=572&item_id=24426')
+      ->answers('<CancelHold><code>BorrowerCannotCancelHold</code></CancelHold>');
+
+
+    $this->assertEquals(['statut' => false,
+                         'erreur' => 'Annulation impossible : Cette réservation ne peut être annulée'],
                         $this->service->supprimerReservation($this->_lafond, '24426'));
   }
 
-- 
GitLab