summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-12-29 14:47:17 +0100
committerChristian Grothoff <christian@grothoff.org>2022-12-29 14:47:17 +0100
commit2c19f6a6fb180f059fcaeb193dd387c4d6af21b1 (patch)
treed7fdd874e84950510f5a7a698007023ed46d80ea /src/testing
parent689bbc7a201067815cb0975703422854099d19ba (diff)
downloadmerchant-2c19f6a6fb180f059fcaeb193dd387c4d6af21b1.tar.gz
merchant-2c19f6a6fb180f059fcaeb193dd387c4d6af21b1.tar.bz2
merchant-2c19f6a6fb180f059fcaeb193dd387c4d6af21b1.zip
-towards fixing the template tests
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_merchant_api.c201
-rw-r--r--src/testing/testing_api_cmd_get_template.c41
-rw-r--r--src/testing/testing_api_cmd_post_templates.c42
-rw-r--r--src/testing/testing_api_cmd_post_using_templates.c116
4 files changed, 195 insertions, 205 deletions
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index a4a6dfd9..a53ec442 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -1299,79 +1299,133 @@ run (void *cls,
MHD_HTTP_OK,
NULL),
TALER_TESTING_cmd_merchant_post_templates ("post-templates-t1",
- merchant_url,
- "template-1",
- "a template",
- MHD_HTTP_NO_CONTENT),
+ merchant_url,
+ "template-1",
+ "a template",
+ MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_merchant_post_templates ("post-templates-t1-idem",
- merchant_url,
- "template-1",
- "a template",
- MHD_HTTP_NO_CONTENT),
+ merchant_url,
+ "template-1",
+ "a template",
+ MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_merchant_post_templates ("post-templates-t1-non-idem",
- merchant_url,
- "template-1",
- "a different template",
- MHD_HTTP_CONFLICT),
+ merchant_url,
+ "template-1",
+ "a different template",
+ MHD_HTTP_CONFLICT),
TALER_TESTING_cmd_merchant_get_templates ("get-templates-t1",
+ merchant_url,
+ MHD_HTTP_OK,
+ "post-templates-t1",
+ NULL),
+ TALER_TESTING_cmd_merchant_get_template ("get-template-t1",
merchant_url,
+ "template-1",
MHD_HTTP_OK,
- "post-templates-t1",
- NULL),
- TALER_TESTING_cmd_merchant_get_template ("get-template-t1",
- merchant_url,
- "template-1",
- MHD_HTTP_OK,
- "post-templates-t1"),
+ "post-templates-t1"),
TALER_TESTING_cmd_merchant_post_templates ("post-templates-t2",
- merchant_url,
- "template-2",
- "a template",
- MHD_HTTP_NO_CONTENT),
- TALER_TESTING_cmd_merchant_patch_template ("patch-templates-t2",
- merchant_url,
- "template-2",
- "another template",
- "data:image/jpeg;base64,RAWDATA",
- json_pack ("{s:s}",
- "summary",
- "EUR"),
- MHD_HTTP_NO_CONTENT),
+ merchant_url,
+ "template-2",
+ "a template",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_patch_template (
+ "patch-templates-t2",
+ merchant_url,
+ "template-2",
+ "another template",
+ "data:image/jpeg;base64,RAWDATA",
+ json_pack ("{s:s}",
+ "summary",
+ "my new summary"),
+ MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_merchant_get_template ("get-template-t2",
- merchant_url,
- "template-2",
- MHD_HTTP_OK,
- "patch-templates-t2"),
+ merchant_url,
+ "template-2",
+ MHD_HTTP_OK,
+ "patch-templates-t2"),
TALER_TESTING_cmd_merchant_get_template ("get-template-nx",
- merchant_url,
- "template-nx",
- MHD_HTTP_NOT_FOUND,
- NULL),
- TALER_TESTING_cmd_merchant_patch_template ("patch-templates-t3-nx",
- merchant_url,
- "template-3",
- "updated template",
- "data:image/jpeg;base64,RAWDATA",
- json_pack ("{s:s}",
- "summary",
- "EUR"),
- MHD_HTTP_NOT_FOUND),
+ merchant_url,
+ "template-nx",
+ MHD_HTTP_NOT_FOUND,
+ NULL),
+ TALER_TESTING_cmd_merchant_patch_template (
+ "patch-templates-t3-nx",
+ merchant_url,
+ "template-3",
+ "updated template",
+ "data:image/jpeg;base64,RAWDATA",
+ json_pack ("{s:s}",
+ "summary",
+ "my new summary"),
+ MHD_HTTP_NOT_FOUND),
+ TALER_TESTING_cmd_merchant_post_templates2 (
+ "post-templates-t3-amount",
+ merchant_url,
+ "template-amount",
+ "a different template with an amount",
+ NULL,
+ json_pack ("{s:s}",
+ "amount",
+ "EUR:4"),
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_post_using_templates (
+ "using-templates-t1",
+ "post-templates-t1",
+ merchant_url,
+ "summary-1",
+ "EUR:10",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_merchant_post_using_templates (
+ "using-templates-t1-amount-missing",
+ "post-templates-t1",
+ merchant_url,
+ "summary-1",
+ NULL,
+ MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_merchant_post_using_templates (
+ "using-templates-t1-summary-missing",
+ "post-templates-t1",
+ merchant_url,
+ NULL,
+ "EUR:10",
+ MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_merchant_post_using_templates (
+ "using-templates-t1-amount-conflict",
+ "post-templates-t3-amount",
+ merchant_url,
+ "summary-1",
+ "EUR:10",
+ MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_merchant_post_using_templates (
+ "using-templates-t1-amount-duplicate",
+ "post-templates-t3-amount",
+ merchant_url,
+ "summary-1",
+ "EUR:4",
+ MHD_HTTP_CONFLICT),
TALER_TESTING_cmd_merchant_delete_template ("get-templates-empty",
- merchant_url,
- "t1",
- MHD_HTTP_NOT_FOUND),
+ merchant_url,
+ "t1",
+ MHD_HTTP_NOT_FOUND),
TALER_TESTING_cmd_merchant_delete_template ("get-templates-empty",
- merchant_url,
- "template-1",
- MHD_HTTP_NO_CONTENT),
+ merchant_url,
+ "template-1",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_post_using_templates (
+ "post-templates-t1-deleted",
+ "post-templates-t1",
+ merchant_url,
+ "summary-1",
+ "EUR:5",
+ MHD_HTTP_NOT_FOUND),
TALER_TESTING_cmd_end ()
- };
+ };
- struct TALER_TESTING_Command webhooks[] = {
+ struct TALER_TESTING_Command webhooks[] = {
TALER_TESTING_cmd_merchant_get_webhooks ("get-webhooks-empty",
- merchant_url,
- MHD_HTTP_OK,
- NULL),
+ merchant_url,
+ MHD_HTTP_OK,
+ NULL),
TALER_TESTING_cmd_merchant_post_webhooks ("post-webhooks-w1",
merchant_url,
"webhook-1",
@@ -1439,31 +1493,8 @@ run (void *cls,
"webhook-1",
MHD_HTTP_NO_CONTENT),
TALER_TESTING_cmd_end ()
- };
+ };
- struct TALER_TESTING_Command using_templates[] = {
- TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t1",
- merchant_url,
- "template-1",
- "EUR:10",
- MHD_HTTP_NO_CONTENT),
- TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t1-idem",
- merchant_url,
- "template-1",
- "EUR:10",
- MHD_HTTP_NO_CONTENT),
- TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t1-non-idem",
- merchant_url,
- "template-1",
- "EUR:5",
- MHD_HTTP_CONFLICT),
- TALER_TESTING_cmd_merchant_post_using_templates ("post-templates-t2",
- merchant_url,
- "template-2",
- "EUR:10",
- MHD_HTTP_NO_CONTENT),
- TALER_TESTING_cmd_end ()
- };
struct TALER_TESTING_Command commands[] = {
/* general setup */
@@ -1819,8 +1850,6 @@ run (void *cls,
templates),
TALER_TESTING_cmd_batch ("webhooks",
webhooks),
- TALER_TESTING_cmd_batch ("using_templates",
- using_templates),
/**
* End the suite.
*/
diff --git a/src/testing/testing_api_cmd_get_template.c b/src/testing/testing_api_cmd_get_template.c
index 4e5580da..2f0f882a 100644
--- a/src/testing/testing_api_cmd_get_template.c
+++ b/src/testing/testing_api_cmd_get_template.c
@@ -78,10 +78,10 @@ struct GetTemplateState
*/
static void
get_template_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr,
- const char *template_description,
- const char *image,
- const json_t *template_contract)
+ const struct TALER_MERCHANT_HttpResponse *hr,
+ const char *template_description,
+ const char *image,
+ const json_t *template_contract)
{
struct GetTemplateState *gis = cls;
const struct TALER_TESTING_Command *template_cmd;
@@ -108,7 +108,7 @@ get_template_cb (void *cls,
gis->template_reference);
if (GNUNET_OK !=
TALER_TESTING_get_trait_template_description (template_cmd,
- &expected_description))
+ &expected_description))
TALER_TESTING_interpreter_fail (gis->is);
if (0 != strcmp (template_description,
*expected_description))
@@ -124,10 +124,13 @@ get_template_cb (void *cls,
if (GNUNET_OK !=
TALER_TESTING_get_trait_template_image (template_cmd,
- &expected_image))
+ &expected_image))
TALER_TESTING_interpreter_fail (gis->is);
- if (0 != strcmp (image,
- *expected_image))
+ if ( ( (NULL == image) && (NULL != *expected_image)) ||
+ ( (NULL != image) && (NULL == *expected_image)) ||
+ ( (NULL != image) &&
+ (0 != strcmp (image,
+ *expected_image)) ) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Template image does not match\n");
@@ -174,17 +177,17 @@ get_template_cb (void *cls,
*/
static void
get_template_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
{
struct GetTemplateState *gis = cls;
gis->is = is;
gis->igh = TALER_MERCHANT_template_get (is->ctx,
- gis->merchant_url,
- gis->template_id,
- &get_template_cb,
- gis);
+ gis->merchant_url,
+ gis->template_id,
+ &get_template_cb,
+ gis);
GNUNET_assert (NULL != gis->igh);
}
@@ -198,7 +201,7 @@ get_template_run (void *cls,
*/
static void
get_template_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
+ const struct TALER_TESTING_Command *cmd)
{
struct GetTemplateState *gis = cls;
@@ -214,10 +217,10 @@ get_template_cleanup (void *cls,
struct TALER_TESTING_Command
TALER_TESTING_cmd_merchant_get_template (const char *label,
- const char *merchant_url,
- const char *template_id,
- unsigned int http_status,
- const char *template_reference)
+ const char *merchant_url,
+ const char *template_id,
+ unsigned int http_status,
+ const char *template_reference)
{
struct GetTemplateState *gis;
diff --git a/src/testing/testing_api_cmd_post_templates.c b/src/testing/testing_api_cmd_post_templates.c
index 3708a467..c80e00cf 100644
--- a/src/testing/testing_api_cmd_post_templates.c
+++ b/src/testing/testing_api_cmd_post_templates.c
@@ -85,7 +85,7 @@ struct PostTemplatesState
*/
static void
post_templates_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr)
+ const struct TALER_MERCHANT_HttpResponse *hr)
{
struct PostTemplatesState *tis = cls;
@@ -130,20 +130,20 @@ post_templates_cb (void *cls,
*/
static void
post_templates_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
{
struct PostTemplatesState *tis = cls;
tis->is = is;
tis->iph = TALER_MERCHANT_templates_post (is->ctx,
- tis->merchant_url,
- tis->template_id,
- tis->template_description,
- tis->image,
- tis->template_contract,
- &post_templates_cb,
- tis);
+ tis->merchant_url,
+ tis->template_id,
+ tis->template_description,
+ tis->image,
+ tis->template_contract,
+ &post_templates_cb,
+ tis);
GNUNET_assert (NULL != tis->iph);
}
@@ -158,11 +158,11 @@ post_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_templates_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
+ const void **ret,
+ const char *trait,
+ unsigned int index)
{
struct PostTemplatesState *pts = cls;
struct TALER_TESTING_Trait traits[] = {
@@ -190,7 +190,7 @@ post_templates_traits (void *cls,
*/
static void
post_templates_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
+ const struct TALER_TESTING_Command *cmd)
{
struct PostTemplatesState *tis = cls;
@@ -226,7 +226,7 @@ TALER_TESTING_cmd_merchant_post_templates2 (
tis->template_id = template_id;
tis->http_status = http_status;
tis->template_description = template_description;
- tis->image = GNUNET_strdup (image);
+ tis->image = (NULL == image) ? NULL : GNUNET_strdup (image);
tis->template_contract = template_contract;
{
struct TALER_TESTING_Command cmd = {
@@ -244,17 +244,17 @@ TALER_TESTING_cmd_merchant_post_templates2 (
struct TALER_TESTING_Command
TALER_TESTING_cmd_merchant_post_templates (const char *label,
- const char *merchant_url,
- const char *template_id,
- const char *template_description,
- unsigned int http_status)
+ const char *merchant_url,
+ const char *template_id,
+ const char *template_description,
+ unsigned int http_status)
{
return TALER_TESTING_cmd_merchant_post_templates2 (
label,
merchant_url,
template_id,
template_description,
- "",
+ NULL,
json_pack ("{s:s}", "merchant", "Pay"),
http_status);
}
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 */