diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-23 17:08:28 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-06-23 17:08:28 -0400 |
commit | d34f954dcaf6d064931d47f0c90576f3b1dbf648 (patch) | |
tree | 90b74e39bee371213d93286eeb5f8a10dc2c3e28 /src/testing/testing_api_cmd_get_products.c | |
parent | d52356b4ac66bc22f3c7195490ff713668f340b1 (diff) | |
download | merchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.tar.gz merchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.tar.bz2 merchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.zip |
harder tests for GET /private/instances, GET /private/products
Diffstat (limited to 'src/testing/testing_api_cmd_get_products.c')
-rw-r--r-- | src/testing/testing_api_cmd_get_products.c | 74 |
1 files changed, 69 insertions, 5 deletions
diff --git a/src/testing/testing_api_cmd_get_products.c b/src/testing/testing_api_cmd_get_products.c index e9e2bd49..8eb50013 100644 --- a/src/testing/testing_api_cmd_get_products.c +++ b/src/testing/testing_api_cmd_get_products.c @@ -54,6 +54,16 @@ struct GetProductsState */ unsigned int http_status; + /** + * The list of product references. + */ + const char **products; + + /** + * Length of @e products. + */ + unsigned int products_length; + }; @@ -71,7 +81,6 @@ get_products_cb (void *cls, unsigned int products_length, const struct TALER_MERCHANT_InventoryEntry products[]) { - /* FIXME, deeper checks should be implemented here. */ struct GetProductsState *gis = cls; gis->igh = NULL; @@ -88,8 +97,43 @@ get_products_cb (void *cls, switch (hr->http_status) { case MHD_HTTP_OK: - // FIXME: use gis->product_reference here to - // check if the data returned matches that from the POST / PATCH + if (products_length != gis->products_length) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Length of products found does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + for (unsigned int i = 0; i < gis->products_length; ++i) + { + const struct TALER_TESTING_Command *product_cmd; + + product_cmd = TALER_TESTING_interpreter_lookup_command ( + gis->is, + gis->products[i]); + + { + const char *product_id; + if (GNUNET_OK != + TALER_TESTING_get_trait_string (product_cmd, + 2, + &product_id)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch product id\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + if (0 != strcmp (products[i].product_id, + product_id)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Product id does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -139,9 +183,12 @@ get_products_cleanup (void *cls, if (NULL != gis->igh) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "GET /products/$ID operation did not complete\n"); + "GET /products operation did not complete\n"); TALER_MERCHANT_products_get_cancel (gis->igh); } + GNUNET_array_grow (gis->products, + gis->products_length, + 0); GNUNET_free (gis); } @@ -153,12 +200,16 @@ get_products_cleanup (void *cls, * @param merchant_url base URL of the merchant serving the * GET /products request. * @param http_status expected HTTP response code. + * @param ... NULL-terminated list of labels (const char *) of + * product (commands) we expect to be returned in the list + * (assuming @a http_code is #MHD_HTTP_OK) * @return the command. */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_products (const char *label, const char *merchant_url, - unsigned int http_status) + unsigned int http_status, + ...) { struct GetProductsState *gis; @@ -166,6 +217,19 @@ TALER_TESTING_cmd_merchant_get_products (const char *label, gis->merchant_url = merchant_url; gis->http_status = http_status; { + const char *clabel; + va_list ap; + + va_start (ap, http_status); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (gis->products, + gis->products_length, + clabel); + } + va_end (ap); + } + { struct TALER_TESTING_Command cmd = { .cls = gis, .label = label, |