gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] 220/277: test for GET /private/reserves


From: gnunet
Subject: [taler-merchant] 220/277: test for GET /private/reserves
Date: Sun, 05 Jul 2020 20:52:13 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

commit 1d22e4f8b263446f24fbdb3d2b92f7c1f2939f48
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Mon Jun 15 19:26:40 2020 -0400

    test for GET /private/reserves
---
 .../taler-merchant-httpd_private-get-reserves.c    |  84 +++-------
 src/include/taler_merchant_testing_lib.h           |  13 ++
 src/lib/merchant_api_get_reserves.c                |  14 +-
 src/lib/merchant_api_get_tips.c                    |   2 +-
 src/lib/merchant_api_wallet_get_order.c            |   2 +-
 src/testing/Makefile.am                            |   1 +
 src/testing/test_merchant_api.c                    |   3 +
 src/testing/testing_api_cmd_get_reserves.c         | 172 +++++++++++++++++++++
 8 files changed, 221 insertions(+), 70 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-reserves.c 
b/src/backend/taler-merchant-httpd_private-get-reserves.c
index be607c0..976d71c 100644
--- a/src/backend/taler-merchant-httpd_private-get-reserves.c
+++ b/src/backend/taler-merchant-httpd_private-get-reserves.c
@@ -50,7 +50,11 @@ add_reserve (void *cls,
              bool active)
 {
   json_t *pa = cls;
+  struct GNUNET_TIME_Absolute creation_time_round = creation_time;
+  struct GNUNET_TIME_Absolute expiration_time_round = expiration_time;
 
+  GNUNET_TIME_round_abs (&creation_time_round);
+  GNUNET_TIME_round_abs (&expiration_time_round);
   GNUNET_assert (0 ==
                  json_array_append_new (
                    pa,
@@ -61,16 +65,16 @@ add_reserve (void *cls,
                      "reserve_pub",
                      GNUNET_JSON_from_data_auto (reserve_pub),
                      "creation_time",
-                     GNUNET_JSON_from_time_abs (creation_time),
+                     GNUNET_JSON_from_time_abs (creation_time_round),
                      "expiration_time",
-                     GNUNET_JSON_from_time_abs (expiration_time),
+                     GNUNET_JSON_from_time_abs (expiration_time_round),
                      "merchant_initial_amount",
                      TALER_JSON_from_amount (merchant_initial_amount),
                      "exchange_initial_amount",
                      TALER_JSON_from_amount (exchange_initial_amount),
                      "pickup_amount",
                      TALER_JSON_from_amount (pickup_amount),
-                     "commited_amount",
+                     "committed_amount",
                      TALER_JSON_from_amount (committed_amount),
                      "active",
                      active)));
@@ -96,68 +100,26 @@ TMH_private_get_reserves (const struct TMH_RequestHandler 
*rh,
   enum TALER_EXCHANGE_YesNoAll active;
   enum TALER_EXCHANGE_YesNoAll failures;
 
+  if (! (TALER_arg_to_yna (connection,
+                           "active",
+                           TALER_EXCHANGE_YNA_ALL,
+                           &active)) )
   {
-    const char *active_s;
-
-    active_s = MHD_lookup_connection_value (connection,
-                                            MHD_GET_ARGUMENT_KIND,
-                                            "active");
-    if (NULL == active_s)
-    {
-      active = TALER_EXCHANGE_YNA_ALL;
-    }
-    else if (0 == strcasecmp (active_s,
-                              "yes"))
-    {
-      active = TALER_EXCHANGE_YNA_YES;
-    }
-    else if (0 == strcasecmp (active_s,
-                              "no"))
-    {
-      active = TALER_EXCHANGE_YNA_NO;
-    }
-    else if (0 == strcasecmp (active_s,
-                              "all"))
-    {
-      active = TALER_EXCHANGE_YNA_ALL;
-    }
-    else
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_BAD_REQUEST,
-                                         TALER_EC_PARAMETER_MALFORMED,
-                                         "active");
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_BAD_REQUEST,
+                                       TALER_EC_PARAMETER_MALFORMED,
+                                       "active");
   }
 
+  if (! (TALER_arg_to_yna (connection,
+                           "failures",
+                           TALER_EXCHANGE_YNA_ALL,
+                           &failures)) )
   {
-    const char *failures_s;
-
-    failures_s = MHD_lookup_connection_value (connection,
-                                              MHD_GET_ARGUMENT_KIND,
-                                              "failures");
-    if (NULL == failures_s)
-    {
-      failures = TALER_EXCHANGE_YNA_ALL;
-    }
-    else if (0 == strcasecmp (failures_s,
-                              "yes"))
-    {
-      failures = TALER_EXCHANGE_YNA_YES;
-    }
-    else if (0 == strcasecmp (failures_s,
-                              "no"))
-    {
-      failures = TALER_EXCHANGE_YNA_NO;
-    }
-    else if (0 == strcasecmp (failures_s,
-                              "all"))
-    {
-      failures = TALER_EXCHANGE_YNA_ALL;
-    }
-    else
-      return TALER_MHD_reply_with_error (connection,
-                                         MHD_HTTP_BAD_REQUEST,
-                                         TALER_EC_PARAMETER_MALFORMED,
-                                         "failures");
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_BAD_REQUEST,
+                                       TALER_EC_PARAMETER_MALFORMED,
+                                       "failures");
   }
 
   ra = json_array ();
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 9fb9e57..83de976 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -583,6 +583,19 @@ TALER_TESTING_cmd_merchant_post_reserves (const char 
*label,
                                           unsigned int http_status);
 
 
+/**
+ * Define a "GET /reserves" CMD
+ *
+ * @param label command label.
+ * @param merchant_url url to the merchant.
+ * @param http_status expected HTTP response code.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserves (const char *label,
+                                         const char *merchant_url,
+                                         unsigned int http_status);
+
+
 /**
  * Define a "DELETE reserve" CMD.
  *
diff --git a/src/lib/merchant_api_get_reserves.c 
b/src/lib/merchant_api_get_reserves.c
index 017dcd9..f524514 100644
--- a/src/lib/merchant_api_get_reserves.c
+++ b/src/lib/merchant_api_get_reserves.c
@@ -132,6 +132,12 @@ handle_reserves_get_finished (void *cls,
         json_array_foreach (reserves, i, reserve) {
           struct TALER_MERCHANT_ReserveSummary *rd = &rds[i];
           struct GNUNET_JSON_Specification ispec[] = {
+            GNUNET_JSON_spec_fixed_auto ("reserve_pub",
+                                         &rd->reserve_pub),
+            GNUNET_JSON_spec_absolute_time ("creation_time",
+                                            &rd->creation_time),
+            GNUNET_JSON_spec_absolute_time ("expiration_time",
+                                            &rd->expiration_time),
             TALER_JSON_spec_amount ("merchant_initial_amount",
                                     &rd->merchant_initial_amount),
             TALER_JSON_spec_amount ("exchange_initial_amount",
@@ -140,12 +146,6 @@ handle_reserves_get_finished (void *cls,
                                     &rd->pickup_amount),
             TALER_JSON_spec_amount ("committed_amount",
                                     &rd->committed_amount),
-            GNUNET_JSON_spec_fixed_auto ("reserve_pub",
-                                         &rd->reserve_pub),
-            GNUNET_JSON_spec_absolute_time ("creation_time",
-                                            &rd->creation_time),
-            GNUNET_JSON_spec_absolute_time ("expiration_time",
-                                            &rd->expiration_time),
             GNUNET_JSON_spec_bool ("active",
                                    &rd->active),
             GNUNET_JSON_spec_end ()
@@ -246,7 +246,7 @@ TALER_MERCHANT_reserves_get (struct GNUNET_CURL_Context 
*ctx,
   after_s = GNUNET_strdup (GNUNET_STRINGS_absolute_time_to_string (
                              after));
   rgh->url = TALER_url_join (backend_url,
-                             "reserves",
+                             "private/reserves",
                              "active",
                              active_s,
                              "failures",
diff --git a/src/lib/merchant_api_get_tips.c b/src/lib/merchant_api_get_tips.c
index d15ed82..ee0ad1b 100644
--- a/src/lib/merchant_api_get_tips.c
+++ b/src/lib/merchant_api_get_tips.c
@@ -220,7 +220,7 @@ TALER_MERCHANT_tips_get (
 {
   return TALER_MERCHANT_tips_get2 (ctx,
                                    backend_url,
-                                   false,
+                                   TALER_EXCHANGE_YNA_NO,
                                    -20,
                                    UINT64_MAX,
                                    cb,
diff --git a/src/lib/merchant_api_wallet_get_order.c 
b/src/lib/merchant_api_wallet_get_order.c
index cdf3db0..799e57f 100644
--- a/src/lib/merchant_api_wallet_get_order.c
+++ b/src/lib/merchant_api_wallet_get_order.c
@@ -494,7 +494,7 @@ TALER_MERCHANT_wallet_order_get (struct GNUNET_CURL_Context 
*ctx,
  * @param owgh handle to the request to be canceled
  */
 void
-TALER_MERCHANT_wallet_get_order_cancel (
+TALER_MERCHANT_wallet_order_get_cancel (
   struct TALER_MERCHANT_OrderWalletGetHandle *owgh)
 {
   if (NULL != owgh->job)
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index c7becfd..8ffe415 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -21,6 +21,7 @@ libtalermerchanttesting_la_SOURCES = \
   testing_api_cmd_get_instances.c \
   testing_api_cmd_get_product.c \
   testing_api_cmd_get_products.c \
+  testing_api_cmd_get_reserves.c \
   testing_api_cmd_get_tips.c \
   testing_api_cmd_get_transfers.c \
   testing_api_cmd_delete_instance.c \
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 05ed298..bc51e4a 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -651,6 +651,9 @@ run (void *cls,
     TALER_TESTING_cmd_get_tips ("get-tips-1",
                                 merchant_url,
                                 MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-1",
+                                             merchant_url,
+                                             MHD_HTTP_OK),
     TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1",
                                                merchant_url,
                                                "create-reserve-tip-1",
diff --git a/src/testing/testing_api_cmd_get_reserves.c 
b/src/testing/testing_api_cmd_get_reserves.c
new file mode 100644
index 0000000..b9909ca
--- /dev/null
+++ b/src/testing/testing_api_cmd_get_reserves.c
@@ -0,0 +1,172 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2020 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as
+  published by the Free Software Foundation; either version 3, or
+  (at your option) any later version.
+
+  TALER is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public
+  License along with TALER; see the file COPYING.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/testing_api_cmd_get_reserves.c
+ * @brief command to test GET /private/reserves
+ * @author Jonathan Buchanan
+ */
+#include "platform.h"
+#include <taler/taler_exchange_service.h>
+#include <taler/taler_testing_lib.h>
+#include "taler_merchant_service.h"
+#include "taler_merchant_testing_lib.h"
+
+
+/**
+ * State of a "GET reserves" CMD
+ */
+struct GetReservesState
+{
+
+  /**
+   * Handle for a "GET reserves" request.
+   */
+  struct TALER_MERCHANT_ReservesGetHandle *rgh;
+
+  /**
+   * The interpreter state.
+   */
+  struct TALER_TESTING_Interpreter *is;
+
+  /**
+   * Base URL of the merchant serving the request.
+   */
+  const char *merchant_url;
+
+  /**
+   * Expected HTTP response code.
+   */
+  unsigned int http_status;
+};
+
+
+static void
+get_reserves_cb (void *cls,
+                 const struct TALER_MERCHANT_HttpResponse *hr,
+                 unsigned int reserves_length,
+                 const struct TALER_MERCHANT_ReserveSummary reserves[])
+{
+  /* FIXME, deeper checks should be implemented here. */
+  struct GetReservesState *grs = cls;
+
+  grs->rgh = NULL;
+  if (grs->http_status != hr->http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u (%d) to command %s\n",
+                hr->http_status,
+                (int) hr->ec,
+                TALER_TESTING_interpreter_get_current_label (grs->is));
+    TALER_TESTING_interpreter_fail (grs->is);
+    return;
+  }
+  switch (hr->http_status)
+  {
+  case MHD_HTTP_OK:
+    // FIXME: check if the data returned matches that from the POST / PATCH
+    break;
+  default:
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Unhandled HTTP status.\n");
+  }
+  TALER_TESTING_interpreter_next (grs->is);
+}
+
+
+/**
+ * Run the "GET /private/reserves" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command being run now.
+ * @param is interpreter state.
+ */
+static void
+get_reserves_run (void *cls,
+                  const struct TALER_TESTING_Command *cmd,
+                  struct TALER_TESTING_Interpreter *is)
+{
+  struct GetReservesState *grs = cls;
+
+  grs->is = is;
+  grs->rgh = TALER_MERCHANT_reserves_get (is->ctx,
+                                          grs->merchant_url,
+                                          GNUNET_TIME_UNIT_ZERO_ABS,
+                                          TALER_EXCHANGE_YNA_ALL,
+                                          TALER_EXCHANGE_YNA_ALL,
+                                          &get_reserves_cb,
+                                          grs);
+
+  GNUNET_assert (NULL != grs->rgh);
+}
+
+
+/**
+ * Free the state of a "GET reserves" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ */
+static void
+get_reserves_cleanup (void *cls,
+                      const struct TALER_TESTING_Command *cmd)
+{
+  struct GetReservesState *grs = cls;
+
+  if (NULL != grs->rgh)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "GET /private/reserves operation did not complete\n");
+    TALER_MERCHANT_reserves_get_cancel (grs->rgh);
+  }
+  GNUNET_free (grs);
+}
+
+
+/**
+ * Define a "GET /reserves" CMD
+ *
+ * @param label command label.
+ * @param merchant_url url to the merchant.
+ * @param http_status expected HTTP response code.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserves (const char *label,
+                                         const char *merchant_url,
+                                         unsigned int http_status)
+{
+  struct GetReservesState *grs;
+
+  grs = GNUNET_new (struct GetReservesState);
+  grs->merchant_url = merchant_url;
+  grs->http_status = http_status;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = grs,
+      .label = label,
+      .run = &get_reserves_run,
+      .cleanup = &get_reserves_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
+/* end of testing_api_cmd_get_reserves.c */

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]