diff options
author | priscilla <priscilla.huang@efrei.net> | 2022-12-29 07:14:09 -0500 |
---|---|---|
committer | priscilla <priscilla.huang@efrei.net> | 2022-12-29 07:14:34 -0500 |
commit | 689bbc7a201067815cb0975703422854099d19ba (patch) | |
tree | d00d3bc13681f299fc28c9d9bcf595484b36c05d /src/testing | |
parent | 99db83bca3b5dbe1399a642eb4192546bbfd24df (diff) | |
download | merchant-689bbc7a201067815cb0975703422854099d19ba.tar.gz merchant-689bbc7a201067815cb0975703422854099d19ba.tar.bz2 merchant-689bbc7a201067815cb0975703422854099d19ba.zip |
using templates testing
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/Makefile.am | 1 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 26 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_using_templates.c | 117 | ||||
-rw-r--r-- | src/testing/testing_api_helpers.c | 1 |
4 files changed, 133 insertions, 12 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index af98f4e1..159b922e 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am @@ -63,6 +63,7 @@ libtalermerchanttesting_la_SOURCES = \ testing_api_cmd_post_reserves.c \ testing_api_cmd_post_transfers.c \ testing_api_cmd_post_templates.c \ + testing_api_cmd_post_using_templates.c \ testing_api_cmd_post_webhooks.c \ testing_api_cmd_patch_instance.c \ testing_api_cmd_patch_product.c \ diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index f6fb28a3..a4a6dfd9 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -1441,6 +1441,30 @@ run (void *cls, 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 */ TALER_TESTING_cmd_auditor_add ("add-auditor-OK", @@ -1795,6 +1819,8 @@ 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_post_using_templates.c b/src/testing/testing_api_cmd_post_using_templates.c index d286364c..6b97aa36 100644 --- a/src/testing/testing_api_cmd_post_using_templates.c +++ b/src/testing/testing_api_cmd_post_using_templates.c @@ -124,14 +124,59 @@ post_using_templates_run (void *cls, struct TALER_TESTING_Interpreter *is) { struct PostUsingTemplatesState *tis = cls; + const char *template_id; tis->is = is; - tis->iph = TALER_MERCHANT_templates_post (is->ctx, - tis->merchant_url, - tis->summary, - tis->amount, - &post_using_templates_cb, - tis); + + const json_t *contract_terms; + const char *error_name; + unsigned int error_line; + const char **proposal_reference; + + if (NULL== cmd) + 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); GNUNET_assert (NULL != tis->iph); } @@ -153,7 +198,7 @@ post_using_templates_traits (void *cls, { struct PostUsingTemplatesState *pts = cls; struct TALER_TESTING_Trait traits[] = { - TALER_TESTING_make_trait_sumamry (&pts->summary), + TALER_TESTING_make_trait_summary (&pts->summary), TALER_TESTING_make_trait_amount (&pts->amount), TALER_TESTING_trait_end (), }; @@ -176,15 +221,63 @@ static void post_using_templates_cleanup (void *cls, const struct TALER_TESTING_Command *cmd) { - struct PostTemplatesState *tis = cls; + struct PostUsingTemplatesState *tis = cls; if (NULL != tis->iph) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "POST /templates operation did not complete\n"); - TALER_MERCHANT_templates_post_cancel (tis->iph); + "POST /using-templates operation did not complete\n"); + TALER_MERCHANT_using_templates_post_cancel (tis->iph); } - GNUNET_free (tis->image); - json_decref (tis->template_contract); GNUNET_free (tis); } + + +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_post_using_templates2 ( + const char *label, + const char *merchant_url, + const char *summary, + const char *amount, + unsigned int http_status) +{ + struct PostUsingTemplatesState *tis; + + tis = GNUNET_new (struct PostUsingTemplatesState); + tis->merchant_url = merchant_url; + tis->http_status = http_status; + tis->summary = summary; + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (amount, + &tis->amount)); + + { + struct TALER_TESTING_Command cmd = { + .cls = tis, + .label = label, + .run = &post_using_templates_run, + .cleanup = &post_using_templates_cleanup, + .traits = &post_using_templates_traits + }; + + return cmd; + } +} + +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 */ diff --git a/src/testing/testing_api_helpers.c b/src/testing/testing_api_helpers.c index 659bb694..ea7f2dea 100644 --- a/src/testing/testing_api_helpers.c +++ b/src/testing/testing_api_helpers.c @@ -1,3 +1,4 @@ + /* This file is part of TALER Copyright (C) 2014-2018 Taler Systems SA |