summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-15 19:26:40 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-15 19:26:40 -0400
commit1d22e4f8b263446f24fbdb3d2b92f7c1f2939f48 (patch)
tree2f2a8495e4b9cd06122eb482e17ba1a1539670eb /src
parentaf158318c6923a51ec8a75bbf2f857ce60cec139 (diff)
downloadmerchant-1d22e4f8b263446f24fbdb3d2b92f7c1f2939f48.tar.gz
merchant-1d22e4f8b263446f24fbdb3d2b92f7c1f2939f48.tar.bz2
merchant-1d22e4f8b263446f24fbdb3d2b92f7c1f2939f48.zip
test for GET /private/reserves
Diffstat (limited to 'src')
-rw-r--r--src/backend/taler-merchant-httpd_private-get-reserves.c84
-rw-r--r--src/include/taler_merchant_testing_lib.h13
-rw-r--r--src/lib/merchant_api_get_reserves.c14
-rw-r--r--src/lib/merchant_api_get_tips.c2
-rw-r--r--src/lib/merchant_api_wallet_get_order.c2
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/test_merchant_api.c3
-rw-r--r--src/testing/testing_api_cmd_get_reserves.c172
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 be607c0e..976d71cb 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 9fb9e573..83de9763 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -584,6 +584,19 @@ TALER_TESTING_cmd_merchant_post_reserves (const char *label,
/**
+ * 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.
*
* @param label command label.
diff --git a/src/lib/merchant_api_get_reserves.c b/src/lib/merchant_api_get_reserves.c
index 017dcd9c..f524514a 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 d15ed820..ee0ad1bf 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 cdf3db03..799e57f5 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 c7becfd7..8ffe4157 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 05ed298c..bc51e4af 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 00000000..b9909cad
--- /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 */