LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_order.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 77.8 % 45 35
Test Date: 2026-09-11 17:45:24 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2020 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify
       6              :   it under the terms of the GNU General Public License as
       7              :   published by the Free Software Foundation; either version 3, or
       8              :   (at your option) any later version.
       9              : 
      10              :   TALER is distributed in the hope that it will be useful, but
      11              :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13              :   GNU General Public License for more details.
      14              : 
      15              :   You should have received a copy of the GNU General Public
      16              :   License along with TALER; see the file COPYING.  If not, see
      17              :   <http://www.gnu.org/licenses/>
      18              : */
      19              : /**
      20              :  * @file src/testing/testing_api_cmd_delete_order.c
      21              :  * @brief command to test DELETE /orders/$ORDER_ID
      22              :  * @author Jonathan Buchanan
      23              :  */
      24              : #include "platform.h"
      25              : struct DeleteOrderState;
      26              : #define TALER_MERCHANT_DELETE_PRIVATE_ORDER_RESULT_CLOSURE struct DeleteOrderState
      27              : #include <taler/taler_exchange_service.h>
      28              : #include <taler/taler_testing_lib.h>
      29              : #include "taler/taler_merchant_service.h"
      30              : #include "taler/taler_merchant_testing_lib.h"
      31              : #include <taler/merchant/delete-private-orders-ORDER_ID.h>
      32              : 
      33              : 
      34              : /**
      35              :  * State of a "DELETE /order/$ORDER_ID" CMD.
      36              :  */
      37              : struct DeleteOrderState
      38              : {
      39              : 
      40              :   /**
      41              :    * Handle for a "DELETE order" request.
      42              :    */
      43              :   struct TALER_MERCHANT_DeletePrivateOrderHandle *odh;
      44              : 
      45              :   /**
      46              :    * The interpreter state.
      47              :    */
      48              :   struct TALER_TESTING_Interpreter *is;
      49              : 
      50              :   /**
      51              :    * Base URL of the merchant serving the request.
      52              :    */
      53              :   const char *merchant_url;
      54              : 
      55              :   /**
      56              :    * ID of the order to run DELETE for.
      57              :    */
      58              :   const char *order_id;
      59              : 
      60              :   /**
      61              :    * Expected HTTP response code.
      62              :    */
      63              :   unsigned int http_status;
      64              : 
      65              :   /**
      66              :    * Force deletion even if externally settled payments exist.
      67              :    */
      68              :   bool force;
      69              : 
      70              : };
      71              : 
      72              : 
      73              : /**
      74              :  * Callback for a DELETE /orders/$ID operation.
      75              :  *
      76              :  * @param cls closure for this function
      77              :  * @param dor response being processed
      78              :  */
      79              : static void
      80           14 : delete_order_cb (struct DeleteOrderState *dos,
      81              :                  const struct TALER_MERCHANT_DeletePrivateOrderResponse *dor)
      82              : {
      83              : 
      84           14 :   dos->odh = NULL;
      85           14 :   if (dos->http_status != dor->hr.http_status)
      86              :   {
      87            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      88              :                 "Unexpected response code %u (%d) to command %s\n",
      89              :                 dor->hr.http_status,
      90              :                 (int) dor->hr.ec,
      91              :                 TALER_TESTING_interpreter_get_current_label (dos->is));
      92            0 :     TALER_TESTING_interpreter_fail (dos->is);
      93            0 :     return;
      94              :   }
      95           14 :   switch (dor->hr.http_status)
      96              :   {
      97            6 :   case MHD_HTTP_NO_CONTENT:
      98            6 :     break;
      99            0 :   case MHD_HTTP_UNAUTHORIZED:
     100            0 :     break;
     101            2 :   case MHD_HTTP_NOT_FOUND:
     102            2 :     break;
     103            6 :   case MHD_HTTP_CONFLICT:
     104            6 :     break;
     105            0 :   default:
     106            0 :     GNUNET_break (0);
     107            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     108              :                 "Unhandled HTTP status %u for DELETE order.\n",
     109              :                 dor->hr.http_status);
     110              :   }
     111           14 :   TALER_TESTING_interpreter_next (dos->is);
     112              : }
     113              : 
     114              : 
     115              : /**
     116              :  * Run the "DELETE order" CMD.
     117              :  *
     118              :  *
     119              :  * @param cls closure.
     120              :  * @param cmd command being run now.
     121              :  * @param is interpreter state.
     122              :  */
     123              : static void
     124           14 : delete_order_run (void *cls,
     125              :                   const struct TALER_TESTING_Command *cmd,
     126              :                   struct TALER_TESTING_Interpreter *is)
     127              : {
     128           14 :   struct DeleteOrderState *dos = cls;
     129              : 
     130           14 :   dos->is = is;
     131           14 :   dos->odh = TALER_MERCHANT_delete_private_order_create (
     132              :     TALER_TESTING_interpreter_get_context (is),
     133              :     dos->merchant_url,
     134              :     dos->order_id);
     135           14 :   if (dos->force)
     136            4 :     GNUNET_assert (GNUNET_OK ==
     137              :                    TALER_MERCHANT_delete_private_order_set_options (
     138              :                      dos->odh,
     139              :                      TALER_MERCHANT_delete_private_order_set_option_force ()));
     140              :   {
     141              :     enum TALER_ErrorCode ec;
     142              : 
     143           14 :     ec = TALER_MERCHANT_delete_private_order_start (dos->odh,
     144              :                                                     &delete_order_cb,
     145              :                                                     dos);
     146           14 :     GNUNET_assert (TALER_EC_NONE == ec);
     147              :   }
     148           14 : }
     149              : 
     150              : 
     151              : /**
     152              :  * Free the state of a "DELETE order" CMD, and possibly
     153              :  * cancel a pending operation thereof.
     154              :  *
     155              :  * @param cls closure.
     156              :  * @param cmd command being run.
     157              :  */
     158              : static void
     159           14 : delete_order_cleanup (void *cls,
     160              :                       const struct TALER_TESTING_Command *cmd)
     161              : {
     162           14 :   struct DeleteOrderState *dos = cls;
     163              : 
     164           14 :   if (NULL != dos->odh)
     165              :   {
     166            0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     167              :                 "DELETE /orders/$ORDER_ID operation did not complete\n");
     168            0 :     TALER_MERCHANT_delete_private_order_cancel (dos->odh);
     169              :   }
     170           14 :   GNUNET_free (dos);
     171           14 : }
     172              : 
     173              : 
     174              : struct TALER_TESTING_Command
     175            6 : TALER_TESTING_cmd_merchant_delete_order (const char *label,
     176              :                                          const char *merchant_url,
     177              :                                          const char *order_id,
     178              :                                          unsigned int http_status)
     179              : {
     180            6 :   return TALER_TESTING_cmd_merchant_delete_order2 (label,
     181              :                                                    merchant_url,
     182              :                                                    order_id,
     183              :                                                    false,
     184              :                                                    http_status);
     185              : }
     186              : 
     187              : 
     188              : struct TALER_TESTING_Command
     189           14 : TALER_TESTING_cmd_merchant_delete_order2 (const char *label,
     190              :                                           const char *merchant_url,
     191              :                                           const char *order_id,
     192              :                                           bool force,
     193              :                                           unsigned int http_status)
     194              : {
     195              :   struct DeleteOrderState *dos;
     196              : 
     197           14 :   dos = GNUNET_new (struct DeleteOrderState);
     198           14 :   dos->merchant_url = merchant_url;
     199           14 :   dos->order_id = order_id;
     200           14 :   dos->http_status = http_status;
     201           14 :   dos->force = force;
     202              :   {
     203           14 :     struct TALER_TESTING_Command cmd = {
     204              :       .cls = dos,
     205              :       .label = label,
     206              :       .run = &delete_order_run,
     207              :       .cleanup = &delete_order_cleanup
     208              :     };
     209              : 
     210           14 :     return cmd;
     211              :   }
     212              : }
        

Generated by: LCOV version 2.0-1