summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_post_using_templates.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_post_using_templates.c')
-rw-r--r--src/testing/testing_api_cmd_post_using_templates.c116
1 files changed, 37 insertions, 79 deletions
diff --git a/src/testing/testing_api_cmd_post_using_templates.c b/src/testing/testing_api_cmd_post_using_templates.c
index 6b97aa36..026d460a 100644
--- a/src/testing/testing_api_cmd_post_using_templates.c
+++ b/src/testing/testing_api_cmd_post_using_templates.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2022 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
@@ -59,6 +59,11 @@ struct PostUsingTemplatesState
struct TALER_Amount amount;
/**
+ * Label of a command that created the template we should use.
+ */
+ const char *template_ref;
+
+ /**
* Expected HTTP response code.
*/
unsigned int http_status;
@@ -91,14 +96,11 @@ post_using_templates_cb (void *cls,
}
switch (hr->http_status)
{
- case MHD_HTTP_NO_CONTENT:
- break;
- case MHD_HTTP_NOT_ACCEPTABLE:
+ case MHD_HTTP_OK:
+ // FIXME: check reply!
break;
case MHD_HTTP_CONFLICT:
break;
- case MHD_HTTP_FORBIDDEN:
- break;
case MHD_HTTP_NOT_FOUND:
break;
default:
@@ -106,10 +108,12 @@ post_using_templates_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Unhandled HTTP status %u for POST /templates/$ID.\n",
hr->http_status);
+ break;
}
TALER_TESTING_interpreter_next (tis->is);
}
+
/**
* Run the "POST /using-templates" CMD.
*
@@ -124,62 +128,30 @@ post_using_templates_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct PostUsingTemplatesState *tis = cls;
- const char *template_id;
+ const struct TALER_TESTING_Command *ref;
+ const char **template_id;
tis->is = is;
-
- const json_t *contract_terms;
- const char *error_name;
- unsigned int error_line;
- const char **proposal_reference;
-
- if (NULL== cmd)
+ ref = TALER_TESTING_interpreter_lookup_command (is,
+ tis->template_ref);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_template_id (ref,
+ &template_id))
TALER_TESTING_FAIL (is);
- {
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_contract_terms (cmd,
- &contract_terms))
- TALER_TESTING_FAIL (is);
- {
- /* Get information that needs to be put verbatim in the
- * deposit permission */
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("template_id",
- &template_id),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (contract_terms,
- spec,
- &error_name,
- &error_line))
- {
- char *js;
- js = json_dumps (contract_terms,
- JSON_INDENT (1));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Parser failed on %s:%u for input `%s'\n",
- error_name,
- error_line,
- js);
- free (js);
- TALER_TESTING_FAIL (is);
- }
- }
- }
-
- tis->iph = TALER_MERCHANT_using_templates_post (is->ctx,
- tis->merchant_url,
- template_id,
- tis->summary,
- &tis->amount,
- &post_using_templates_cb,
- tis);
+ tis->iph = TALER_MERCHANT_using_templates_post (
+ is->ctx,
+ tis->merchant_url,
+ *template_id,
+ tis->summary,
+ TALER_amount_is_valid (&tis->amount)
+ ? &tis->amount
+ : NULL,
+ &post_using_templates_cb,
+ tis);
GNUNET_assert (NULL != tis->iph);
}
+
/**
* Offers information from the POST /using-templates CMD state to other
* commands.
@@ -190,7 +162,7 @@ post_using_templates_run (void *cls,
* @param index index number of the object to extract.
* @return #GNUNET_OK on success
*/
-static int
+static enum GNUNET_GenericReturnValue
post_using_templates_traits (void *cls,
const void **ret,
const char *trait,
@@ -198,11 +170,10 @@ post_using_templates_traits (void *cls,
{
struct PostUsingTemplatesState *pts = cls;
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_summary (&pts->summary),
- TALER_TESTING_make_trait_amount (&pts->amount),
TALER_TESTING_trait_end (),
};
+ (void) pts;
return TALER_TESTING_get_trait (traits,
ret,
trait,
@@ -234,8 +205,9 @@ post_using_templates_cleanup (void *cls,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_using_templates2 (
+TALER_TESTING_cmd_merchant_post_using_templates (
const char *label,
+ const char *template_ref,
const char *merchant_url,
const char *summary,
const char *amount,
@@ -244,13 +216,14 @@ TALER_TESTING_cmd_merchant_post_using_templates2 (
struct PostUsingTemplatesState *tis;
tis = GNUNET_new (struct PostUsingTemplatesState);
+ tis->template_ref = template_ref;
tis->merchant_url = merchant_url;
tis->http_status = http_status;
tis->summary = summary;
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (amount,
- &tis->amount));
-
+ if (NULL != amount)
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (amount,
+ &tis->amount));
{
struct TALER_TESTING_Command cmd = {
.cls = tis,
@@ -264,20 +237,5 @@ TALER_TESTING_cmd_merchant_post_using_templates2 (
}
}
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_using_templates (const char *label,
- const char *merchant_url,
- const char *summary,
- const char *amount,
- unsigned int http_status)
-{
- return TALER_TESTING_cmd_merchant_post_using_templates2 (
- label,
- merchant_url,
- summary,
- amount,
- http_status);
-}
-
/* end of testing_api_cmd_post_using_templates.c */