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-08 16:38:55 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-08 16:38:55 -0400
commit071554a7ac031cc859355b5ee353a708c0c5cea5 (patch)
tree1a1474f59e0645669f56018abb9f3f487230247f /src/testing/testing_api_cmd_post_orders.c
parenta5e33f1a6d3f865a7c169783c63007cfdd3c30eb (diff)
downloadmerchant-071554a7ac031cc859355b5ee353a708c0c5cea5.tar.gz
merchant-071554a7ac031cc859355b5ee353a708c0c5cea5.tar.bz2
merchant-071554a7ac031cc859355b5ee353a708c0c5cea5.zip
removed more old code, more tests for post order, some twister tests for merchant-exchange requests
Diffstat (limited to 'src/testing/testing_api_cmd_post_orders.c')
-rw-r--r--src/testing/testing_api_cmd_post_orders.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c
index 0a1db61d..243dbca3 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -96,6 +96,11 @@ struct OrdersState
* Merchant public key.
*/
struct TALER_MerchantPublicKeyP merchant_pub;
+
+ /**
+ * The payment target for the order
+ */
+ const char *payment_target;
};
@@ -320,6 +325,70 @@ orders_run (void *cls,
/**
+ * Run a "orders" CMD.
+ *
+ * @param cls closure.
+ * @param cmd command currently being run.
+ * @param is interpreter state.
+ */
+static void
+orders_run2 (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct OrdersState *ps = cls;
+ json_t *order;
+ json_error_t error;
+
+ ps->is = is;
+ order = json_loads (ps->order,
+ JSON_REJECT_DUPLICATES,
+ &error);
+ if (NULL == order)
+ {
+ // human error here.
+ GNUNET_break (0);
+ fprintf (stderr, "%s\n", error.text);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+
+ if (NULL == json_object_get (order,
+ "order_id"))
+ {
+ struct GNUNET_TIME_Absolute now;
+ char *order_id;
+
+ // FIXME: should probably use get_monotone() to ensure uniqueness!
+ now = GNUNET_TIME_absolute_get ();
+ order_id = GNUNET_STRINGS_data_to_string_alloc
+ (&now.abs_value_us,
+ sizeof (now.abs_value_us));
+ json_object_set_new (order,
+ "order_id",
+ json_string (order_id));
+ GNUNET_free (order_id);
+ }
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &ps->nonce,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+ ps->po = TALER_MERCHANT_orders_post2 (is->ctx,
+ ps->merchant_url,
+ order,
+ GNUNET_TIME_UNIT_ZERO,
+ ps->payment_target,
+ 0,
+ NULL,
+ 0,
+ NULL,
+ &order_cb,
+ ps);
+ json_decref (order);
+ GNUNET_assert (NULL != ps->po);
+}
+
+
+/**
* Free the state of a "orders" CMD, and possibly
* cancel it if it did not complete.
*
@@ -392,3 +461,42 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label,
return cmd;
}
}
+
+
+/**
+ * Make the "proposal" command.
+ *
+ * @param label command label
+ * @param merchant_url base URL of the merchant serving
+ * the proposal request.
+ * @param http_status expected HTTP status.
+ * @param order the order to PUT to the merchant.
+ * @param payment_target payment target for the order.
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_post_orders2 (const char *label,
+ const char *merchant_url,
+ unsigned int http_status,
+ const char *order,
+ const char *payment_target)
+{
+ struct OrdersState *ps;
+
+ ps = GNUNET_new (struct OrdersState);
+ ps->order = order;
+ ps->http_status = http_status;
+ ps->merchant_url = merchant_url;
+ ps->payment_target = payment_target;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ps,
+ .label = label,
+ .run = &orders_run2,
+ .cleanup = &orders_cleanup,
+ .traits = &orders_traits
+ };
+
+ return cmd;
+ }
+}