/*
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
*/
/**
* @file lib/testing_api_cmd_get_transfers.c
* @brief command to test GET /transfers.
* @author Marcello Stanisci
* @author Christian Grothoff
*/
#include "platform.h"
#include
#include
#include "taler_merchant_service.h"
#include "taler_merchant_testing_lib.h"
/**
* State of a GET transfers 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_EXCHANGE_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 */