merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_delete_donau_instances.c (4909B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2024 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Lesser General Public License as published by the Free Software
      7   Foundation; either version 2.1, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful,
     10   but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     11   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
     12 
     13   You should have received a copy of the GNU Lesser General Public License along with TALER;
     14   see the file COPYING.LGPL.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file testing_api_cmd_delete_donau_instances.c
     18  * @brief Command to test DELETE /donau/$charity_id request
     19  * @author Bohdan Potuzhnyi
     20  * @author Vlada Svirsh
     21  */
     22 
     23 #include "taler/platform.h"
     24 #include <taler/taler_testing_lib.h>
     25 #include "taler/taler_merchant_service.h"
     26 #include "taler/taler_merchant_testing_lib.h"
     27 #include <taler/taler-merchant/delete-private-donau-DONAU_SERIAL.h>
     28 
     29 /**
     30  * State for DELETE /donau/$charity_id testing command.
     31  */
     32 struct DeleteDonauState
     33 {
     34   /**
     35    * Handle for a DELETE /donau request.
     36    */
     37   struct TALER_MERCHANT_DeletePrivateDonauHandle *ddh;
     38 
     39   /**
     40    * The interpreter state.
     41    */
     42   struct TALER_TESTING_Interpreter *is;
     43 
     44   /**
     45    * Base URL of the Donau service.
     46    */
     47   const char *url;
     48 
     49   /**
     50    * Charity ID to delete.
     51    */
     52   uint64_t charity_id;
     53 
     54   /**
     55    * Expected HTTP response code.
     56    */
     57   unsigned int expected_http_status;
     58 };
     59 
     60 /**
     61  * Callback for DELETE /donau/$charity_id operation.
     62  *
     63  * @param cls closure for this function
     64  * @param hr HTTP response details
     65  */
     66 static void
     67 delete_donau_cb (void *cls,
     68                  const struct TALER_MERCHANT_DeletePrivateDonauResponse *ddr)
     69 {
     70   struct DeleteDonauState *dds = cls;
     71 
     72   dds->ddh = NULL;
     73 
     74   if (dds->expected_http_status != ddr->hr.http_status)
     75   {
     76     TALER_TESTING_unexpected_status_with_body (
     77       dds->is,
     78       ddr->hr.http_status,
     79       dds->expected_http_status,
     80       ddr->hr.reply);
     81     TALER_TESTING_interpreter_fail (dds->is);
     82     return;
     83   }
     84 
     85   switch (ddr->hr.http_status)
     86   {
     87   case MHD_HTTP_NO_CONTENT:
     88     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     89                 "DELETE /donau succeeded\n");
     90     break;
     91   case MHD_HTTP_NOT_FOUND:
     92     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     93                 "DELETE /donau: Charity not found\n");
     94     break;
     95   case MHD_HTTP_UNAUTHORIZED:
     96     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     97                 "DELETE /donau: Unauthorized access\n");
     98     break;
     99   default:
    100     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
    101                 "Unhandled HTTP status %u\n",
    102                 ddr->hr.http_status);
    103   }
    104 
    105   TALER_TESTING_interpreter_next (dds->is);
    106 }
    107 
    108 
    109 /**
    110  * Run the DELETE /donau/$charity_id test command.
    111  *
    112  * @param cls closure.
    113  * @param cmd command being run now.
    114  * @param is interpreter state.
    115  */
    116 static void
    117 delete_donau_run (void *cls,
    118                   const struct TALER_TESTING_Command *cmd,
    119                   struct TALER_TESTING_Interpreter *is)
    120 {
    121   struct DeleteDonauState *dds = cls;
    122 
    123   dds->is = is;
    124   dds->ddh = TALER_MERCHANT_delete_private_donau_create (
    125     TALER_TESTING_interpreter_get_context (is),
    126     dds->url,
    127     dds->charity_id);
    128   {
    129     enum TALER_ErrorCode ec;
    130 
    131     ec = TALER_MERCHANT_delete_private_donau_start (dds->ddh,
    132                                                     &delete_donau_cb,
    133                                                     dds);
    134     GNUNET_assert (TALER_EC_NONE == ec);
    135   }
    136 }
    137 
    138 
    139 /**
    140  * Clean up state for DELETE /donau/$charity_id command.
    141  *
    142  * @param cls closure.
    143  * @param cmd command being run.
    144  */
    145 static void
    146 delete_donau_cleanup (void *cls,
    147                       const struct TALER_TESTING_Command *cmd)
    148 {
    149   struct DeleteDonauState *dds = cls;
    150 
    151   if (NULL != dds->ddh)
    152   {
    153     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
    154                 "DELETE /donau/$charity_id operation did not complete\n");
    155     TALER_MERCHANT_delete_private_donau_cancel (dds->ddh);
    156   }
    157   GNUNET_free (dds);
    158 }
    159 
    160 
    161 /**
    162  * Create a DELETE /donau/$charity_id testing command.
    163  */
    164 struct TALER_TESTING_Command
    165 TALER_TESTING_cmd_merchant_delete_donau_instance (const char *label,
    166                                                   const char *url,
    167                                                   uint64_t charity_id,
    168                                                   unsigned int
    169                                                   expected_http_status)
    170 {
    171   struct DeleteDonauState *dds = GNUNET_new (struct DeleteDonauState);
    172 
    173   dds->url = url;
    174   dds->charity_id = charity_id;
    175   dds->expected_http_status = expected_http_status;
    176 
    177   {
    178     struct TALER_TESTING_Command cmd = {
    179       .cls = dds,
    180       .label = label,
    181       .run = &delete_donau_run,
    182       .cleanup = &delete_donau_cleanup
    183     };
    184 
    185     return cmd;
    186   }
    187 
    188 }