LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_delete_order.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 40 0.0 %
Date: 2022-08-25 06:17:04 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          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 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             : #include <taler/taler_exchange_service.h>
      26             : #include <taler/taler_testing_lib.h>
      27             : #include "taler_merchant_service.h"
      28             : #include "taler_merchant_testing_lib.h"
      29             : 
      30             : 
      31             : /**
      32             :  * State of a "DELETE /order/$ORDER_ID" CMD.
      33             :  */
      34             : struct DeleteOrderState
      35             : {
      36             : 
      37             :   /**
      38             :    * Handle for a "DELETE order" request.
      39             :    */
      40             :   struct TALER_MERCHANT_OrderDeleteHandle *odh;
      41             : 
      42             :   /**
      43             :    * The interpreter state.
      44             :    */
      45             :   struct TALER_TESTING_Interpreter *is;
      46             : 
      47             :   /**
      48             :    * Base URL of the merchant serving the request.
      49             :    */
      50             :   const char *merchant_url;
      51             : 
      52             :   /**
      53             :    * ID of the order to run DELETE for.
      54             :    */
      55             :   const char *order_id;
      56             : 
      57             :   /**
      58             :    * Expected HTTP response code.
      59             :    */
      60             :   unsigned int http_status;
      61             : 
      62             : };
      63             : 
      64             : 
      65             : /**
      66             :  * Callback for a DELETE /orders/$ID operation.
      67             :  *
      68             :  * @param cls closure for this function
      69             :  * @param hr response being processed
      70             :  */
      71             : static void
      72           0 : delete_order_cb (void *cls,
      73             :                  const struct TALER_MERCHANT_HttpResponse *hr)
      74             : {
      75           0 :   struct DeleteOrderState *dos = cls;
      76             : 
      77           0 :   dos->odh = NULL;
      78           0 :   if (dos->http_status != hr->http_status)
      79             :   {
      80           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      81             :                 "Unexpected response code %u (%d) to command %s\n",
      82             :                 hr->http_status,
      83             :                 (int) hr->ec,
      84             :                 TALER_TESTING_interpreter_get_current_label (dos->is));
      85           0 :     TALER_TESTING_interpreter_fail (dos->is);
      86           0 :     return;
      87             :   }
      88           0 :   switch (hr->http_status)
      89             :   {
      90           0 :   case MHD_HTTP_NO_CONTENT:
      91           0 :     break;
      92           0 :   case MHD_HTTP_UNAUTHORIZED:
      93           0 :     break;
      94           0 :   case MHD_HTTP_NOT_FOUND:
      95           0 :     break;
      96           0 :   case MHD_HTTP_CONFLICT:
      97           0 :     break;
      98           0 :   default:
      99           0 :     GNUNET_break (0);
     100           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     101             :                 "Unhandled HTTP status %u for DELETE order.\n",
     102             :                 hr->http_status);
     103             :   }
     104           0 :   TALER_TESTING_interpreter_next (dos->is);
     105             : }
     106             : 
     107             : 
     108             : /**
     109             :  * Run the "DELETE order" CMD.
     110             :  *
     111             :  *
     112             :  * @param cls closure.
     113             :  * @param cmd command being run now.
     114             :  * @param is interpreter state.
     115             :  */
     116             : static void
     117           0 : delete_order_run (void *cls,
     118             :                   const struct TALER_TESTING_Command *cmd,
     119             :                   struct TALER_TESTING_Interpreter *is)
     120             : {
     121           0 :   struct DeleteOrderState *dos = cls;
     122             : 
     123           0 :   dos->is = is;
     124           0 :   dos->odh = TALER_MERCHANT_order_delete (is->ctx,
     125             :                                           dos->merchant_url,
     126             :                                           dos->order_id,
     127             :                                           false, /* FIXME: support testing force... */
     128             :                                           &delete_order_cb,
     129             :                                           dos);
     130           0 :   GNUNET_assert (NULL != dos->odh);
     131           0 : }
     132             : 
     133             : 
     134             : /**
     135             :  * Free the state of a "DELETE order" CMD, and possibly
     136             :  * cancel a pending operation thereof.
     137             :  *
     138             :  * @param cls closure.
     139             :  * @param cmd command being run.
     140             :  */
     141             : static void
     142           0 : delete_order_cleanup (void *cls,
     143             :                       const struct TALER_TESTING_Command *cmd)
     144             : {
     145           0 :   struct DeleteOrderState *dos = cls;
     146             : 
     147           0 :   if (NULL != dos->odh)
     148             :   {
     149           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     150             :                 "DELETE /orders/$ORDER_ID operation did not complete\n");
     151           0 :     TALER_MERCHANT_order_delete_cancel (dos->odh);
     152             :   }
     153           0 :   GNUNET_free (dos);
     154           0 : }
     155             : 
     156             : 
     157             : struct TALER_TESTING_Command
     158           0 : TALER_TESTING_cmd_merchant_delete_order (const char *label,
     159             :                                          const char *merchant_url,
     160             :                                          const char *order_id,
     161             :                                          unsigned int http_status)
     162             : {
     163             :   struct DeleteOrderState *dos;
     164             : 
     165           0 :   dos = GNUNET_new (struct DeleteOrderState);
     166           0 :   dos->merchant_url = merchant_url;
     167           0 :   dos->order_id = order_id;
     168           0 :   dos->http_status = http_status;
     169             :   {
     170           0 :     struct TALER_TESTING_Command cmd = {
     171             :       .cls = dos,
     172             :       .label = label,
     173             :       .run = &delete_order_run,
     174             :       .cleanup = &delete_order_cleanup
     175             :     };
     176             : 
     177           0 :     return cmd;
     178             :   }
     179             : }

Generated by: LCOV version 1.14