LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_forget_order.c (source / functions) Hit Total Coverage
Test: GNU Taler coverage report Lines: 0 51 0.0 %
Date: 2020-08-15 06:12:35 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 exchange/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             :                                           0,
     160             :                                           &order_id))
     161           0 :       TALER_TESTING_FAIL (is);
     162             :   }
     163           0 :   ofs->ofh = TALER_MERCHANT_order_forget (is->ctx,
     164             :                                           ofs->merchant_url,
     165             :                                           order_id,
     166             :                                           ofs->paths_length,
     167             :                                           ofs->paths,
     168             :                                           &order_forget_cb,
     169             :                                           ofs);
     170           0 :   GNUNET_assert (NULL != ofs->ofh);
     171             : }
     172             : 
     173             : 
     174             : /**
     175             :  * Offer internal data to other commands.
     176             :  *
     177             :  * @param cls closure
     178             :  * @param ret[out] result (could be anything)
     179             :  * @param trait name of the trait
     180             :  * @param index index number of the object to extract.
     181             :  * @return #GNUNET_OK on success
     182             :  */
     183             : static int
     184           0 : order_forget_traits (void *cls,
     185             :                      const void **ret,
     186             :                      const char *trait,
     187             :                      unsigned int index)
     188           0 : {
     189           0 :   struct OrderForgetState *ofs = cls;
     190           0 :   struct TALER_TESTING_Trait traits[ofs->paths_length + 2];
     191             : 
     192           0 :   traits[0] = TALER_TESTING_make_trait_uint32 (0,
     193           0 :                                                &ofs->paths_length);
     194           0 :   for (unsigned int i = 0; i < ofs->paths_length; ++i)
     195           0 :     traits[i + 1] = TALER_TESTING_make_trait_string (i,
     196           0 :                                                      ofs->paths[i]);
     197           0 :   traits[ofs->paths_length + 1] = TALER_TESTING_trait_end ();
     198             : 
     199           0 :   return TALER_TESTING_get_trait (traits,
     200             :                                   ret,
     201             :                                   trait,
     202             :                                   index);
     203             : }
     204             : 
     205             : 
     206             : /**
     207             :  * Make a "order forget" command.
     208             :  *
     209             :  * @param label command label.
     210             :  * @param merchant_url base URL of the merchant backend
     211             :  *        serving the order claim request.
     212             :  * @param http_status expected HTTP response code.
     213             :  * @param order_reference reference to a POST order CMD, can be NULL if @a order_id given
     214             :  * @param order_id order id to forget for, can be NULL (then we use @a order_reference)
     215             :  * @param ... NULL-terminated list of paths (const char *) to forget in
     216             :  *        the contract terms.
     217             :  * @return the command.
     218             :  */
     219             : struct TALER_TESTING_Command
     220           0 : TALER_TESTING_cmd_merchant_forget_order (
     221             :   const char *label,
     222             :   const char *merchant_url,
     223             :   unsigned int http_status,
     224             :   const char *order_reference,
     225             :   const char *order_id,
     226             :   ...)
     227             : {
     228             :   struct OrderForgetState *ofs;
     229             : 
     230           0 :   ofs = GNUNET_new (struct OrderForgetState);
     231           0 :   ofs->http_status = http_status;
     232           0 :   ofs->order_reference = order_reference;
     233           0 :   ofs->merchant_url = merchant_url;
     234           0 :   ofs->order_id = order_id;
     235             :   {
     236             :     const char *path;
     237             :     va_list ap;
     238             : 
     239           0 :     va_start (ap, order_id);
     240           0 :     while (NULL != (path = va_arg (ap, const char *)))
     241             :     {
     242           0 :       GNUNET_array_append (ofs->paths,
     243             :                            ofs->paths_length,
     244             :                            path);
     245             :     }
     246           0 :     va_end (ap);
     247             :   }
     248             :   {
     249           0 :     struct TALER_TESTING_Command cmd = {
     250             :       .cls = ofs,
     251             :       .label = label,
     252             :       .run = &order_forget_run,
     253             :       .cleanup = &order_forget_cleanup,
     254             :       .traits = &order_forget_traits
     255             :     };
     256             : 
     257           0 :     return cmd;
     258             :   }
     259             : }

Generated by: LCOV version 1.14