LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_forget_order.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 50 0.0 %
Date: 2022-08-25 06:17:04 Functions: 0 5 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             : /**
      21             :  * @file testing_api_cmd_forget_order.c
      22             :  * @brief command to forget fields of an order
      23             :  * @author Jonathan Buchanan
      24             :  */
      25             : #include "platform.h"
      26             : #include <taler/taler_exchange_service.h>
      27             : #include <taler/taler_testing_lib.h>
      28             : #include "taler_merchant_service.h"
      29             : #include "taler_merchant_testing_lib.h"
      30             : 
      31             : 
      32             : /**
      33             :  * State for a "order forget" CMD.
      34             :  */
      35             : struct OrderForgetState
      36             : {
      37             :   /**
      38             :    * The interpreter state.
      39             :    */
      40             :   struct TALER_TESTING_Interpreter *is;
      41             : 
      42             :   /**
      43             :    * URL of the merchant backend.
      44             :    */
      45             :   const char *merchant_url;
      46             : 
      47             :   /**
      48             :    * Expected status code.
      49             :    */
      50             :   unsigned int http_status;
      51             : 
      52             :   /**
      53             :    * PATCH /orders/$ORDER_ID/forget operation handle.
      54             :    */
      55             :   struct TALER_MERCHANT_OrderForgetHandle *ofh;
      56             : 
      57             :   /**
      58             :    * Reference to a order operation.
      59             :    */
      60             :   const char *order_reference;
      61             : 
      62             :   /**
      63             :    * Order id to forget for. If NULL, the @a order_reference
      64             :    * will offer this value.
      65             :    */
      66             :   const char *order_id;
      67             : 
      68             :   /**
      69             :    * The list of paths to forget in the contract terms.
      70             :    */
      71             :   const char **paths;
      72             : 
      73             :   /**
      74             :    * The length of @e paths.
      75             :    */
      76             :   unsigned int paths_length;
      77             : };
      78             : 
      79             : 
      80             : /**
      81             :  * Free the state of a "order forget" CMD, and possibly
      82             :  * cancel it if it did not complete.
      83             :  *
      84             :  * @param cls closure.
      85             :  * @param cmd command being freed.
      86             :  */
      87             : static void
      88           0 : order_forget_cleanup (void *cls,
      89             :                       const struct TALER_TESTING_Command *cmd)
      90             : {
      91           0 :   struct OrderForgetState *ofs = cls;
      92             : 
      93           0 :   if (NULL != ofs->ofh)
      94             :   {
      95           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
      96             :                 "Command '%s' did not complete\n",
      97             :                 cmd->label);
      98           0 :     TALER_MERCHANT_order_forget_cancel (ofs->ofh);
      99           0 :     ofs->ofh = NULL;
     100             :   }
     101           0 :   GNUNET_array_grow (ofs->paths,
     102             :                      ofs->paths_length,
     103             :                      0);
     104           0 :   GNUNET_free (ofs);
     105           0 : }
     106             : 
     107             : 
     108             : /**
     109             :  * Callback for "order forget" operation, to check the
     110             :  * response code is as expected.
     111             :  *
     112             :  * @param cls closure
     113             :  * @param hr HTTP response we got
     114             :  */
     115             : static void
     116           0 : order_forget_cb (void *cls,
     117             :                  const struct TALER_MERCHANT_HttpResponse *hr)
     118             : {
     119           0 :   struct OrderForgetState *ofs = cls;
     120             : 
     121           0 :   ofs->ofh = NULL;
     122           0 :   if (ofs->http_status != hr->http_status)
     123           0 :     TALER_TESTING_FAIL (ofs->is);
     124           0 :   TALER_TESTING_interpreter_next (ofs->is);
     125             : }
     126             : 
     127             : 
     128             : /**
     129             :  * Run the "order forget" CMD.
     130             :  *
     131             :  * @param cls closure.
     132             :  * @param cmd command currently being run.
     133             :  * @param is interpreter state.
     134             :  */
     135             : static void
     136           0 : order_forget_run (void *cls,
     137             :                   const struct TALER_TESTING_Command *cmd,
     138             :                   struct TALER_TESTING_Interpreter *is)
     139             : {
     140           0 :   struct OrderForgetState *ofs = cls;
     141             :   const char **order_id;
     142             : 
     143           0 :   ofs->is = is;
     144           0 :   if (NULL != ofs->order_id)
     145             :   {
     146           0 :     order_id = &ofs->order_id;
     147             :   }
     148             :   else
     149             :   {
     150             :     const struct TALER_TESTING_Command *order_cmd;
     151             : 
     152             :     order_cmd
     153           0 :       = TALER_TESTING_interpreter_lookup_command (is,
     154             :                                                   ofs->order_reference);
     155           0 :     if (NULL == order_cmd)
     156           0 :       TALER_TESTING_FAIL (is);
     157           0 :     if (GNUNET_OK !=
     158           0 :         TALER_TESTING_get_trait_order_id (order_cmd,
     159             :                                           &order_id))
     160           0 :       TALER_TESTING_FAIL (is);
     161             :   }
     162           0 :   ofs->ofh = TALER_MERCHANT_order_forget (is->ctx,
     163             :                                           ofs->merchant_url,
     164             :                                           *order_id,
     165             :                                           ofs->paths_length,
     166             :                                           ofs->paths,
     167             :                                           &order_forget_cb,
     168             :                                           ofs);
     169           0 :   GNUNET_assert (NULL != ofs->ofh);
     170             : }
     171             : 
     172             : 
     173             : /**
     174             :  * Offer internal data to other commands.
     175             :  *
     176             :  * @param cls closure
     177             :  * @param[out] ret result (could be anything)
     178             :  * @param trait name of the trait
     179             :  * @param index index number of the object to extract.
     180             :  * @return #GNUNET_OK on success
     181             :  */
     182             : static enum GNUNET_GenericReturnValue
     183           0 : order_forget_traits (void *cls,
     184             :                      const void **ret,
     185             :                      const char *trait,
     186             :                      unsigned int index)
     187           0 : {
     188           0 :   struct OrderForgetState *ofs = cls;
     189           0 :   struct TALER_TESTING_Trait traits[ofs->paths_length + 2];
     190             : 
     191           0 :   traits[0] = TALER_TESTING_make_trait_paths_length (&ofs->paths_length);
     192           0 :   for (unsigned int i = 0; i < ofs->paths_length; ++i)
     193           0 :     traits[i + 1] = TALER_TESTING_make_trait_paths (i,
     194           0 :                                                     &ofs->paths[i]);
     195           0 :   traits[ofs->paths_length + 1] = TALER_TESTING_trait_end ();
     196             : 
     197           0 :   return TALER_TESTING_get_trait (traits,
     198             :                                   ret,
     199             :                                   trait,
     200             :                                   index);
     201             : }
     202             : 
     203             : 
     204             : struct TALER_TESTING_Command
     205           0 : TALER_TESTING_cmd_merchant_forget_order (
     206             :   const char *label,
     207             :   const char *merchant_url,
     208             :   unsigned int http_status,
     209             :   const char *order_reference,
     210             :   const char *order_id,
     211             :   ...)
     212             : {
     213             :   struct OrderForgetState *ofs;
     214             : 
     215           0 :   ofs = GNUNET_new (struct OrderForgetState);
     216           0 :   ofs->http_status = http_status;
     217           0 :   ofs->order_reference = order_reference;
     218           0 :   ofs->merchant_url = merchant_url;
     219           0 :   ofs->order_id = order_id;
     220             :   {
     221             :     const char *path;
     222             :     va_list ap;
     223             : 
     224           0 :     va_start (ap, order_id);
     225           0 :     while (NULL != (path = va_arg (ap, const char *)))
     226             :     {
     227           0 :       GNUNET_array_append (ofs->paths,
     228             :                            ofs->paths_length,
     229             :                            path);
     230             :     }
     231           0 :     va_end (ap);
     232             :   }
     233             :   {
     234           0 :     struct TALER_TESTING_Command cmd = {
     235             :       .cls = ofs,
     236             :       .label = label,
     237             :       .run = &order_forget_run,
     238             :       .cleanup = &order_forget_cleanup,
     239             :       .traits = &order_forget_traits
     240             :     };
     241             : 
     242           0 :     return cmd;
     243             :   }
     244             : }

Generated by: LCOV version 1.14