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

Generated by: LCOV version 2.0-1