diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-15 21:08:33 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-15 21:08:33 -0400 |
commit | 63c035bfffaec9b245da58828f7d6504278fc46e (patch) | |
tree | d0cf387fb1545bfcfb5f413236d92b6033ef721e /src/testing | |
parent | 1d22e4f8b263446f24fbdb3d2b92f7c1f2939f48 (diff) | |
download | merchant-63c035bfffaec9b245da58828f7d6504278fc46e.tar.gz merchant-63c035bfffaec9b245da58828f7d6504278fc46e.tar.bz2 merchant-63c035bfffaec9b245da58828f7d6504278fc46e.zip |
test for GET /private/reserves/
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/Makefile.am | 1 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 9 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_reserve.c | 197 |
3 files changed, 205 insertions, 2 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 8ffe4157..6a3aedaa 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_reserve.c \ testing_api_cmd_get_reserves.c \ testing_api_cmd_get_tips.c \ testing_api_cmd_get_transfers.c \ diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index bc51e4af..c2ed9535 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -654,15 +654,20 @@ run (void *cls, TALER_TESTING_cmd_merchant_get_reserves ("get-reserves-1", merchant_url, MHD_HTTP_OK), + TALER_TESTING_cmd_merchant_get_reserve ("get-reserve-1", + merchant_url, + MHD_HTTP_OK, + "create-reserve-tip-1"), + TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1", merchant_url, "create-reserve-tip-1", MHD_HTTP_NO_CONTENT), - TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-tip-1", + TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-tip-2", merchant_url, "create-reserve-tip-1", MHD_HTTP_NO_CONTENT), - TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-tip-1", + TALER_TESTING_cmd_merchant_purge_reserve ("delete-reserve-tip-3", merchant_url, "create-reserve-tip-1", MHD_HTTP_NOT_FOUND), diff --git a/src/testing/testing_api_cmd_get_reserve.c b/src/testing/testing_api_cmd_get_reserve.c new file mode 100644 index 00000000..1cae418e --- /dev/null +++ b/src/testing/testing_api_cmd_get_reserve.c @@ -0,0 +1,197 @@ +/* + 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_reserve.c + * @brief command to test GET /private/reserves/$RESERVE_PUB + * @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" + + +struct GetReserveState +{ + + /** + * Handle for a "GET reserve" request. + */ + struct TALER_MERCHANT_ReserveGetHandle *rgh; + + /** + * The interpreter state. + */ + struct TALER_TESTING_Interpreter *is; + + /** + * Base URL of the merchant serving the request. + */ + const char *merchant_url; + + /** + * Label for a command that created a reserve. + */ + const char *reserve_reference; + + /** + * Expected HTTP response code. + */ + unsigned int http_status; + + /** + * Fetch tips + */ + bool fetch_tips; +}; + + +static void +get_reserve_cb (void *cls, + const struct TALER_MERCHANT_HttpResponse *hr, + const struct TALER_MERCHANT_ReserveSummary *rs, + unsigned int tips_length, + const struct TALER_MERCHANT_TipDetails tips[]) +{ + /* FIXME, deeper checks should be implemented here. */ + struct GetReserveState *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: use grs->reserve_reference here to + // 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/$RESERVE_PUB" CMD. + * + * @param cls closure. + * @param cmd command being run now. + * @param is interpreter state. + */ +static void +get_reserve_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct GetReserveState *grs = cls; + const struct TALER_TESTING_Command *reserve_cmd; + const struct TALER_ReservePublicKeyP *reserve_pub; + + reserve_cmd = TALER_TESTING_interpreter_lookup_command ( + is, + grs->reserve_reference); + if (GNUNET_OK != + TALER_TESTING_get_trait_reserve_pub (reserve_cmd, + 0, + &reserve_pub)) + TALER_TESTING_FAIL (is); + + grs->is = is; + grs->rgh = TALER_MERCHANT_reserve_get (is->ctx, + grs->merchant_url, + reserve_pub, + grs->fetch_tips, + &get_reserve_cb, + grs); + + GNUNET_assert (NULL != grs->rgh); +} + + +/** + * Free the state of a "GET reserve" CMD, and possibly + * cancel a pending operation thereof. + * + * @param cls closure. + * @param cmd command being run. + */ +static void +get_reserve_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct GetReserveState *grs = cls; + + if (NULL != grs->rgh) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "GET /private/reserve/$RESERVE_PUB operation did not complete\n"); + TALER_MERCHANT_reserve_get_cancel (grs->rgh); + } + GNUNET_free (grs); +} + + +/** + * Define a "GET reserve" CMD. + * + * @param label command label. + * @param merchant_url base URL of the merchant serving the request. + * @param http_status expected HTTP response code. + * @param reserve_reference reference to a "POST /reserves" that provides the + * information we are expecting. + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_get_reserve (const char *label, + const char *merchant_url, + unsigned int http_status, + const char *reserve_reference) +{ + struct GetReserveState *grs; + + grs = GNUNET_new (struct GetReserveState); + grs->merchant_url = merchant_url; + grs->http_status = http_status; + grs->reserve_reference = reserve_reference; + grs->fetch_tips = false; + { + struct TALER_TESTING_Command cmd = { + .cls = grs, + .label = label, + .run = &get_reserve_run, + .cleanup = &get_reserve_cleanup + }; + + return cmd; + } +} + + +/* end of testing_api_cmd_get_reserve.c */ |