diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-09 15:47:45 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-09 15:47:45 -0400 |
commit | 6737ee287534892ead4bfa6cea599886705b7afa (patch) | |
tree | 67b77f787457933e508a1cd0c108ed7acc8b2735 /src/testing/testing_api_cmd_post_orders.c | |
parent | 071554a7ac031cc859355b5ee353a708c0c5cea5 (diff) | |
download | merchant-6737ee287534892ead4bfa6cea599886705b7afa.tar.gz merchant-6737ee287534892ead4bfa6cea599886705b7afa.tar.bz2 merchant-6737ee287534892ead4bfa6cea599886705b7afa.zip |
test post orders with products and lock uuids
Diffstat (limited to 'src/testing/testing_api_cmd_post_orders.c')
-rw-r--r-- | src/testing/testing_api_cmd_post_orders.c | 103 |
1 files changed, 98 insertions, 5 deletions
diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c index 243dbca3..0e4f47af 100644 --- a/src/testing/testing_api_cmd_post_orders.c +++ b/src/testing/testing_api_cmd_post_orders.c @@ -101,6 +101,16 @@ struct OrdersState * The payment target for the order */ const char *payment_target; + + /** + * The products the order is purchasing. + */ + const char *products; + + /** + * The locks that the order should release. + */ + const char *locks; }; @@ -340,6 +350,15 @@ orders_run2 (void *cls, json_t *order; json_error_t error; + char *products_string = GNUNET_strdup (ps->products); + char *locks_string = GNUNET_strdup (ps->locks); + char *token; + + struct TALER_MERCHANT_InventoryProduct *products = NULL; + unsigned int products_length = 0; + struct GNUNET_Uuid *locks = NULL; + unsigned int locks_length = 0; + ps->is = is; order = json_loads (ps->order, JSON_REJECT_DUPLICATES, @@ -372,18 +391,83 @@ orders_run2 (void *cls, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &ps->nonce, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)); + for (token = strtok (products_string, ";"); + NULL != token; + token = strtok (NULL, ";")) + { + char *ctok; + struct TALER_MERCHANT_InventoryProduct pd; + + /* Token syntax is "[product_id]/[quantity]" */ + ctok = strchr (token, '/'); + if (NULL != ctok) + { + *ctok = '\0'; + ctok++; + if (1 != sscanf (ctok, + "%u", + &pd.quantity)) + { + GNUNET_break (0); + break; + } + } + else + { + pd.quantity = 1; + } + pd.product_id = token; + + GNUNET_array_append (products, + products_length, + pd); + } + for (token = strtok (locks_string, ";"); + NULL != token; + token = strtok (NULL, ";")) + { + const struct TALER_TESTING_Command *lock_cmd; + struct GNUNET_Uuid *uuid; + + lock_cmd = TALER_TESTING_interpreter_lookup_command ( + is, + token); + + if (GNUNET_OK != + TALER_TESTING_get_trait_uuid (lock_cmd, + 0, + &uuid)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch lock uuid\n"); + TALER_TESTING_interpreter_fail (is); + return; + } + + GNUNET_array_append (locks, + locks_length, + *uuid); + } ps->po = TALER_MERCHANT_orders_post2 (is->ctx, ps->merchant_url, order, GNUNET_TIME_UNIT_ZERO, ps->payment_target, - 0, - NULL, - 0, - NULL, + products_length, + products, + locks_length, + locks, &order_cb, ps); json_decref (order); + GNUNET_free (products_string); + GNUNET_free (locks_string); + GNUNET_array_grow (products, + products_length, + 0); + GNUNET_array_grow (locks, + locks_length, + 0); GNUNET_assert (NULL != ps->po); } @@ -472,6 +556,11 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label, * @param http_status expected HTTP status. * @param order the order to PUT to the merchant. * @param payment_target payment target for the order. + * @param products a string indicating the products this order will be + * purchasing. Should be formatted as + * "[product_id]/[quantity];...". + * @param locks a string of references to lock product commands that should + * be formatted as "[lock_1];[lock_2];...". * @return the command */ struct TALER_TESTING_Command @@ -479,7 +568,9 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char *label, const char *merchant_url, unsigned int http_status, const char *order, - const char *payment_target) + const char *payment_target, + const char *products, + const char *locks) { struct OrdersState *ps; @@ -488,6 +579,8 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char *label, ps->http_status = http_status; ps->merchant_url = merchant_url; ps->payment_target = payment_target; + ps->products = products; + ps->locks = locks; { struct TALER_TESTING_Command cmd = { .cls = ps, |