diff options
author | priscilla <priscilla.huang@efrei.net> | 2023-01-03 07:19:03 -0500 |
---|---|---|
committer | priscilla <priscilla.huang@efrei.net> | 2023-01-03 07:19:03 -0500 |
commit | 11d161bf3e688739407364900dbd6dca6f1dade8 (patch) | |
tree | aff6a1449bc0013a74dd1521583dbab98de399cd | |
parent | dbd6edd6617647208e59665bcdbf7ce985a4ed28 (diff) |
test ok for templates and using templates
-rw-r--r-- | src/backend/taler-merchant-httpd_private-patch-templates-ID.c | 8 | ||||
-rw-r--r-- | src/lib/merchant_api_get_template.c | 4 | ||||
-rw-r--r-- | src/lib/merchant_api_patch_template.c | 5 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 33 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_template.c | 6 |
5 files changed, 30 insertions, 26 deletions
diff --git a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c b/src/backend/taler-merchant-httpd_private-patch-templates-ID.c index 9494d506..82227799 100644 --- a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c +++ b/src/backend/taler-merchant-httpd_private-patch-templates-ID.c @@ -116,10 +116,8 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh, GNUNET_JSON_spec_string ("image", (const char **) &tp.image), NULL), - GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("template_contract", - &tp.template_contract), - NULL), + GNUNET_JSON_spec_json ("template_contract", + &tp.template_contract), GNUNET_JSON_spec_end () }; @@ -148,8 +146,6 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh, } - if (NULL == tp.image) - tp.image = ""; if (! TMH_image_data_url_valid (tp.image)) { GNUNET_break_op (0); diff --git a/src/lib/merchant_api_get_template.c b/src/lib/merchant_api_get_template.c index b2dc2b86..5d2e5961 100644 --- a/src/lib/merchant_api_get_template.c +++ b/src/lib/merchant_api_get_template.c @@ -93,7 +93,7 @@ handle_get_template_finished (void *cls, case MHD_HTTP_OK: { const char *template_description; - const char *image = NULL; + const char *image; json_t *template_contract; bool rst_ok = true; struct GNUNET_JSON_Specification spec[] = { @@ -176,7 +176,7 @@ TALER_MERCHANT_template_get ( char *path; GNUNET_asprintf (&path, - "private/templcdates/%s", + "private/templates/%s", template_id); tgh->url = TALER_url_join (backend_url, path, diff --git a/src/lib/merchant_api_patch_template.c b/src/lib/merchant_api_patch_template.c index da3af08b..0829b222 100644 --- a/src/lib/merchant_api_patch_template.c +++ b/src/lib/merchant_api_patch_template.c @@ -172,8 +172,9 @@ TALER_MERCHANT_template_patch ( req_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("template_description", template_description), - GNUNET_JSON_pack_string ("image", - image), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("image", + image)), GNUNET_JSON_pack_object_incref ("template_contract", (json_t *) template_contract)); tph = GNUNET_new (struct TALER_MERCHANT_TemplatePatchHandle); diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index 591a2c8f..a04bbe57 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -1334,9 +1334,10 @@ run (void *cls, "template-2", "another template", "data:image/jpeg;base64,RAWDATA", - json_pack ("{s:s}", - "summary", - "my new summary"), + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("minimum_age", 0), + GNUNET_JSON_pack_time_rel ("pay_duration", + GNUNET_TIME_UNIT_MINUTES)), MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_get_template ("get-template-t2", merchant_url, @@ -1354,9 +1355,10 @@ run (void *cls, "template-3", "updated template", "data:image/jpeg;base64,RAWDATA", - json_pack ("{s:s}", - "summary", - "my new summary"), + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("minimum_age", 0), + GNUNET_JSON_pack_time_rel ("pay_duration", + GNUNET_TIME_UNIT_MINUTES)), MHD_HTTP_NOT_FOUND), TALER_TESTING_cmd_merchant_post_templates2 ( "post-templates-t3-amount", @@ -1364,41 +1366,44 @@ run (void *cls, "template-amount", "a different template with an amount", NULL, - json_pack ("{s:s}", - "amount", - "EUR:4"), + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("minimum_age", 0), + GNUNET_JSON_pack_time_rel ("pay_duration", + GNUNET_TIME_UNIT_MINUTES), + GNUNET_JSON_pack_string ("amount", + "EUR:4")), MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_post_using_templates ( "using-templates-t1", - "template-1", + "post-templates-t1", merchant_url, "summary-1", "EUR:10", MHD_HTTP_OK), TALER_TESTING_cmd_merchant_post_using_templates ( "using-templates-t1-amount-missing", - "template-1", + "post-templates-t1", merchant_url, "summary-1", NULL, MHD_HTTP_CONFLICT), TALER_TESTING_cmd_merchant_post_using_templates ( "using-templates-t1-summary-missing", - "template-1", + "post-templates-t1", merchant_url, NULL, "EUR:10", MHD_HTTP_CONFLICT), TALER_TESTING_cmd_merchant_post_using_templates ( "using-templates-t1-amount-conflict", - "template-amount", + "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", - "template-amount", + "post-templates-t3-amount", merchant_url, "summary-1", "EUR:4", diff --git a/src/testing/testing_api_cmd_get_template.c b/src/testing/testing_api_cmd_get_template.c index 44568b89..633f1ba5 100644 --- a/src/testing/testing_api_cmd_get_template.c +++ b/src/testing/testing_api_cmd_get_template.c @@ -128,12 +128,14 @@ get_template_cb (void *cls, TALER_TESTING_interpreter_fail (gis->is); if ( ( (NULL == image) && (NULL != *expected_image)) || ( (NULL != image) && (NULL == *expected_image)) || - ( (NULL == image) && + ( (NULL != image) && (0 != strcmp (image, *expected_image)) ) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Template image does not match\n"); + "Template image `%s' does not match `%s'\n", + image, + *expected_image); TALER_TESTING_interpreter_fail (gis->is); return; } |