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.c95
1 files changed, 89 insertions, 6 deletions
diff --git a/src/testing/testing_api_cmd_post_using_templates.c b/src/testing/testing_api_cmd_post_using_templates.c
index 88fe9f9b..a68ea8fe 100644
--- a/src/testing/testing_api_cmd_post_using_templates.c
+++ b/src/testing/testing_api_cmd_post_using_templates.c
@@ -27,6 +27,8 @@
#include "taler_merchant_service.h"
#include "taler_merchant_testing_lib.h"
+
+
/**
* State of a "POST /templates" CMD.
*/
@@ -56,6 +58,11 @@ struct PostUsingTemplatesState
const char *merchant_url;
/**
+ * ID of the using template to run.
+ */
+ const char *using_template_id;
+
+ /**
* Summary given by the customer.
*/
const char *summary;
@@ -144,8 +151,8 @@ struct PostUsingTemplatesState
};
/**
- * Used to fill the "orders" CMD state with backend-provided
- * values. Also double-checks that the order was correctly
+ * Used to fill the "using_template" CMD state with backend-provided
+ * values. Also double-checks that the using_template was correctly
* created.
*
* @param cls closure
@@ -155,7 +162,7 @@ struct PostUsingTemplatesState
* @param hash hash over the contract
*/
static void
-orders_claim_cb (void *cls,
+using_claim_cb (void *cls,
const struct TALER_MERCHANT_HttpResponse *hr,
const json_t *contract_terms,
const struct TALER_MerchantSignatureP *sig,
@@ -324,7 +331,7 @@ post_using_templates_cb (void *cls,
tis->order_id,
&tis->nonce,
&tis->claim_token,
- &orders_claim_cb,
+ &using_claim_cb,
tis)))
TALER_TESTING_FAIL (tis->is);
}
@@ -404,8 +411,8 @@ post_using_templates_traits (void *cls,
TALER_TESTING_make_trait_merchant_pub (&pts->merchant_pub),
TALER_TESTING_make_trait_claim_nonce (&pts->nonce),
TALER_TESTING_make_trait_claim_token (&pts->claim_token),
- TALER_TESTING_make_trait_template_pos_key (&pts->template_pos_key), // extract from template creation CMD
- TALER_TESTING_make_trait_template_pos_alg (&pts->template_pos_alg),
+ TALER_TESTING_make_trait_template_pos_key (pts->template_pos_key), // extract from template creation CMD
+ TALER_TESTING_make_trait_template_pos_alg (pts->template_pos_alg),
TALER_TESTING_trait_end (),
};
@@ -440,13 +447,83 @@ post_using_templates_cleanup (void *cls,
}
+/**
+ * Mark part of the contract terms as possible to forget.
+ *
+ * @param cls pointer to the result of the forget operation.
+ * @param object_id name of the object to forget.
+ * @param parent parent of the object at @e object_id.
+ */
+static void
+mark_forgettable (void *cls,
+ const char *object_id,
+ json_t *parent)
+{
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_mark_forgettable (parent,
+ object_id));
+}
+
+
+/**
+ * Constructs the json for a POST using template request.
+ *
+ * @param using_template_id the name of the using_template to add, can be NULL.
+ * @param refund_deadline the deadline for refunds on this using template.
+ * @param pay_deadline the deadline for payment on this using template.
+ * @param amount the amount this using template is for.
+ * @param[out] using_template where to write the json string.
+ */
+static void
+make_order_json (const char *using_template_id,
+ struct GNUNET_TIME_Timestamp refund_deadline,
+ struct GNUNET_TIME_Timestamp pay_deadline,
+ const char *amount,
+ json_t **using_template)
+{
+ struct GNUNET_TIME_Timestamp refund = refund_deadline;
+ struct GNUNET_TIME_Timestamp pay = pay_deadline;
+ json_t *contract_terms;
+
+ /* Include required fields and some dummy objects to test forgetting. */
+ contract_terms = json_pack (
+ "{s:s, s:s?, s:s, s:s, s:o, s:o, s:s, s:[{s:s}, {s:s}, {s:s}]}",
+ "summary", "merchant-lib testcase",
+ "using_template_id", using_template_id,
+ "amount", amount,
+ "fulfillment_url", "https://example.com",
+ "refund_deadline", GNUNET_JSON_from_timestamp (refund),
+ "pay_deadline", GNUNET_JSON_from_timestamp (pay),
+ "dummy_obj", "EUR:1.0",
+ "dummy_array", /* For testing forgetting parts of arrays */
+ "item", "speakers",
+ "item", "headphones",
+ "item", "earbuds"
+ );
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_expand_path (contract_terms,
+ "$.dummy_obj",
+ &mark_forgettable,
+ NULL));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_expand_path (contract_terms,
+ "$.dummy_array[*].item",
+ &mark_forgettable,
+ NULL));
+ *using_template = contract_terms;
+}
+
+
struct TALER_TESTING_Command
TALER_TESTING_cmd_merchant_post_using_templates (
const char *label,
const char *template_ref,
const char *merchant_url,
+ const char *using_template_id,
const char *summary,
const char *amount,
+ struct GNUNET_TIME_Timestamp refund_deadline,
+ struct GNUNET_TIME_Timestamp pay_deadline,
unsigned int http_status)
{
struct PostUsingTemplatesState *tis;
@@ -454,8 +531,14 @@ TALER_TESTING_cmd_merchant_post_using_templates (
tis = GNUNET_new (struct PostUsingTemplatesState);
tis->template_ref = template_ref;
tis->merchant_url = merchant_url;
+ tis->using_template_id = using_template_id;
tis->http_status = http_status;
tis->summary = summary;
+ make_order_json (using_template_id,
+ refund_deadline,
+ pay_deadline,
+ amount,
+ &tis->order_terms);
if (NULL != amount)
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (amount,