diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-05-13 19:15:14 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-05-13 19:15:14 +0200 |
commit | 9bac37cbe6a2774782a515458098883bbf98b4b6 (patch) | |
tree | c1be0b61cea40afdee565527fa76fb72cb560c8f /src/testing/testing_api_cmd_get_transfers.c | |
parent | a48af85c36a3340ee9303b57428f2929b08995e4 (diff) | |
download | merchant-9bac37cbe6a2774782a515458098883bbf98b4b6.tar.gz merchant-9bac37cbe6a2774782a515458098883bbf98b4b6.tar.bz2 merchant-9bac37cbe6a2774782a515458098883bbf98b4b6.zip |
sketch for GET /transfers cmd
Diffstat (limited to 'src/testing/testing_api_cmd_get_transfers.c')
-rw-r--r-- | src/testing/testing_api_cmd_get_transfers.c | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/src/testing/testing_api_cmd_get_transfers.c b/src/testing/testing_api_cmd_get_transfers.c new file mode 100644 index 00000000..2f8e01d8 --- /dev/null +++ b/src/testing/testing_api_cmd_get_transfers.c @@ -0,0 +1,232 @@ +/* + This file is part of TALER + Copyright (C) 2014-2018, 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_transfers.c + * @brief command to test GET /transfers. + * @author Marcello Stanisci + * @author Christian Grothoff + */ +#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 transfer" CMD. + */ +struct GetTransfersState +{ + + /** + * Handle for a "get transfer" request. + */ + struct TALER_MERCHANT_GetTransfersHandle *gth; + + /** + * The interpreter state. + */ + struct TALER_TESTING_Interpreter *is; + + /** + * Base URL of the merchant serving the request. + */ + const char *merchant_url; + + /** + * payto URI of the merchant to filter by. + */ + const char *payto_uri; + + /** + * Expected HTTP response code. + */ + unsigned int http_status; + + /** + * Reference for a "check bank" CMD. It offers the + * WTID to get. + */ + const char *check_bank_reference; + + /** + * Array of POST /transfer command labels we expect to see listed. + */ + const char **transfers; + + /** + * Length of @e transfers. + */ + unsigned int transfers_length; + +}; + + +/** + * Check the result of our GET /transfers request to a merchant + * + * @param cls closure + * @param hr HTTP response details + * @param transfers_length length of the @a transfers array + * @param transfers array with details about the transfers we received + */ +static void +get_transfers_cb ( + void *cls, + const struct TALER_MERCHANT_HttpResponse *hr, + unsigned int transfers_length, + const struct TALER_MERCHANT_TransferData transfers[]) +{ + struct GetTransfersState *gts = cls; + + gts->gth = NULL; + if (gts->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 (gts->is)); + TALER_TESTING_interpreter_fail (gts->is); + return; + } + switch (hr->http_status) + { + case MHD_HTTP_OK: + { + // FIXME: check that list of returned transactions matches our expectations! + } + break; + default: + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unhandled HTTP status.\n"); + } + TALER_TESTING_interpreter_next (gts->is); +} + + +/** + * Run the "get transfer" CMD. + * + * @param cls closure. + * @param cmd command being run now. + * @param is interpreter state. + */ +static void +get_transfers_run (void *cls, + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) +{ + struct GetTransfersState *gts = cls; + + gts->is = is; + gts->gth = TALER_MERCHANT_transfers_get (is->ctx, + gts->merchant_url, + gts->payto_uri, + GNUNET_TIME_UNIT_FOREVER_ABS, + GNUNET_TIME_UNIT_ZERO_ABS, + INT64_MAX, + 0, + TALER_MERCHANT_YNA_ALL, + &get_transfers_cb, + gts); + GNUNET_assert (NULL != gts->gth); +} + + +/** + * Free the state of a "get transfer" CMD, and possibly + * cancel a pending operation thereof. + * + * @param cls closure. + * @param cmd command being run. + */ +static void +get_transfers_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) +{ + struct GetTransfersState *gts = cls; + + if (NULL != gts->gth) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "GET /transfer operation did not complete\n"); + TALER_MERCHANT_transfers_get_cancel (gts->gth); + } + GNUNET_array_grow (gts->transfers, + gts->transfers_length, + 0); + GNUNET_free (gts); +} + + +/** + * Define a GET /transfers CMD. + * + * @param label command label. + * @param merchant_url base URL of the backend serving the + * "refund increase" request. + * @param payto_uri payto URI to filter by, NULL for no filter + * @param http_code expected HTTP response code + * @param ... NULL-terminated list of labels (const char *) of + * transfer (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) + * @return the command. + */ +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_get_transfers (const char *label, + const char *merchant_url, + const char *payto_uri, + unsigned int http_code, + ...) +{ + struct GetTransfersState *gts; + + gts = GNUNET_new (struct GetTransfersState); + gts->merchant_url = merchant_url; + gts->payto_uri = payto_uri; + gts->http_status = http_code; + { + const char *clabel; + va_list ap; + + va_start (ap, http_code); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (gts->transfers, + gts->transfers_length, + clabel); + } + va_end (ap); + } + { + struct TALER_TESTING_Command cmd = { + .cls = gts, + .label = label, + .run = &get_transfers_run, + .cleanup = &get_transfers_cleanup + }; + + return cmd; + } +} + + +/* end of testing_api_cmd_get_transfers.c */ |