summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_post_orders.c
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-21 16:45:06 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-21 16:45:06 -0400
commitaeef085a936545f26c5be60b33e2d9e05b862492 (patch)
tree961077a2aebe3ac7a2e5b1c445b985c859ec61be /src/testing/testing_api_cmd_post_orders.c
parent9b943e700bf01d3cd45d0b69e93cc4e586a041d0 (diff)
downloadmerchant-aeef085a936545f26c5be60b33e2d9e05b862492.tar.gz
merchant-aeef085a936545f26c5be60b33e2d9e05b862492.tar.bz2
merchant-aeef085a936545f26c5be60b33e2d9e05b862492.zip
fully implement forget + some tests
Diffstat (limited to 'src/testing/testing_api_cmd_post_orders.c')
-rw-r--r--src/testing/testing_api_cmd_post_orders.c75
1 files changed, 36 insertions, 39 deletions
diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c
index 2090c0a4..89369853 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -522,14 +522,30 @@ orders_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 order request.
*
* @param order_id the name of the order to add.
* @param refund_deadline the deadline for refunds on this order.
* @param pay_deadline the deadline for payment on this order.
* @param amount the amount this order is for.
- * @param forgettable a list of paths to mark as forgettable.
- * @param forgettable_length length of @e forgettable.
* @param order[out] where to write the json string.
*/
static void
@@ -537,8 +553,6 @@ make_order_json (const char *order_id,
struct GNUNET_TIME_Absolute refund_deadline,
struct GNUNET_TIME_Absolute pay_deadline,
const char *amount,
- const char **forgettable,
- unsigned int forgettable_length,
char **order)
{
struct GNUNET_TIME_Absolute refund = refund_deadline;
@@ -549,22 +563,32 @@ make_order_json (const char *order_id,
GNUNET_TIME_round_abs (&refund);
GNUNET_TIME_round_abs (&pay);
- /* FIXME: support deeper paths */
-
+ /* 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:s, s:o, s:o, s:s, s:[{s:s}, {s:s}, {s:s}]}",
"summary", "merchant-lib testcase",
"order_id", order_id,
"amount", amount,
"fulfillment_url", "https://example.com",
"refund_deadline", GNUNET_JSON_from_time_abs (refund),
"pay_deadline", GNUNET_JSON_from_time_abs (pay),
- "max_fee", "EUR:1.0"
+ "dummy_obj", "EUR:1.0",
+ "dummy_array", /* For testing forgetting parts of arrays */
+ "item", "speakers",
+ "item", "headphones",
+ "item", "earbuds"
);
- for (unsigned int i = 0; i < forgettable_length; ++i)
- TALER_JSON_contract_mark_forgettable (contract_terms,
- forgettable[i]);
+ 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));
*order = json_dumps (contract_terms, 0);
json_decref (contract_terms);
@@ -602,8 +626,6 @@ TALER_TESTING_cmd_merchant_post_orders_no_claim (const char *label,
refund_deadline,
pay_deadline,
amount,
- NULL,
- 0,
&ps->order);
ps->http_status = http_status;
ps->merchant_url = merchant_url;
@@ -653,8 +675,6 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label,
refund_deadline,
pay_deadline,
amount,
- NULL,
- 0,
&ps->order);
ps->http_status = http_status;
ps->merchant_url = merchant_url;
@@ -706,40 +726,17 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char *label,
const char *amount,
const char *payment_target,
const char *products,
- const char *locks,
- ...)
+ const char *locks)
{
struct OrdersState *ps;
- const char **forgettable = NULL;
- unsigned int forgettable_length = 0;
- {
- const char *path;
- va_list ap;
-
- va_start (ap, locks);
- while (NULL != (path = va_arg (ap, const char *)))
- {
- GNUNET_array_append (forgettable,
- forgettable_length,
- path);
- }
- va_end (ap);
- }
-
ps = GNUNET_new (struct OrdersState);
make_order_json (order_id,
refund_deadline,
pay_deadline,
amount,
- forgettable,
- forgettable_length,
&ps->order);
- GNUNET_array_grow (forgettable,
- forgettable_length,
- 0);
-
ps->http_status = http_status;
ps->merchant_url = merchant_url;
ps->payment_target = payment_target;