From d34f954dcaf6d064931d47f0c90576f3b1dbf648 Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Tue, 23 Jun 2020 17:08:28 -0400 Subject: harder tests for GET /private/instances, GET /private/products --- src/backenddb/test_merchantdb.c | 1 + src/include/taler_merchant_testing_lib.h | 14 +++- src/testing/test_merchant_api.c | 14 +++- src/testing/testing_api_cmd_get_instances.c | 98 ++++++++++++++++++++++-- src/testing/testing_api_cmd_get_products.c | 74 ++++++++++++++++-- src/testing/testing_api_cmd_merchant_get_order.c | 5 ++ src/testing/testing_api_cmd_patch_instance.c | 1 + src/testing/testing_api_cmd_patch_product.c | 1 + src/testing/testing_api_cmd_post_instances.c | 1 + src/testing/testing_api_cmd_post_products.c | 1 + 10 files changed, 193 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index 55ea947d..59699d00 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -3068,6 +3068,7 @@ lookup_reserve_cb (void *cls, const struct TALER_Amount *exchange_initial_amount, const struct TALER_Amount *picked_up_amount, const struct TALER_Amount *committed_amount, + bool active, unsigned int tips_length, const struct TALER_MERCHANTDB_TipDetails *tips) { diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index 787075b5..e96d5fe5 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -88,12 +88,16 @@ TALER_TESTING_cmd_config (const char *label, * @param merchant_url base URL of the merchant serving the * GET /instances 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_instances (const char *label, const char *merchant_url, - unsigned int http_status); + unsigned int http_status, + ...); /** @@ -247,7 +251,7 @@ TALER_TESTING_cmd_merchant_delete_instance (const char *label, unsigned int http_status); -/* ******************* /products**************** */ +/* ******************* /products **************** */ /** @@ -362,12 +366,16 @@ TALER_TESTING_cmd_merchant_patch_product ( * @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, + ...); /** diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index 224a8076..0a150a94 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -958,7 +958,8 @@ run (void *cls, MHD_HTTP_OK), TALER_TESTING_cmd_merchant_get_instances ("instances-empty", merchant_url, - MHD_HTTP_OK), + MHD_HTTP_OK, + NULL), TALER_TESTING_cmd_merchant_post_instances ("instance-create-i1", merchant_url, "i1", @@ -967,7 +968,9 @@ run (void *cls, MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_get_instances ("instances-get-i1", merchant_url, - MHD_HTTP_OK), + MHD_HTTP_OK, + "instance-create-i1", + NULL), TALER_TESTING_cmd_merchant_get_instance ("instances-get-i1", merchant_url, "i1", @@ -1028,7 +1031,8 @@ run (void *cls, MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_get_products ("get-products-empty", merchant_url, - MHD_HTTP_OK), + MHD_HTTP_OK, + NULL), TALER_TESTING_cmd_merchant_post_products ("post-products-p1", merchant_url, "product-1", @@ -1037,7 +1041,9 @@ run (void *cls, MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_get_products ("get-products-p1", merchant_url, - MHD_HTTP_OK), + MHD_HTTP_OK, + "post-products-p1", + NULL), TALER_TESTING_cmd_merchant_get_product ("get-product-p1", merchant_url, "product-1", diff --git a/src/testing/testing_api_cmd_get_instances.c b/src/testing/testing_api_cmd_get_instances.c index 3c93d0ed..5a7c55cb 100644 --- a/src/testing/testing_api_cmd_get_instances.c +++ b/src/testing/testing_api_cmd_get_instances.c @@ -54,6 +54,16 @@ struct GetInstancesState */ unsigned int http_status; + /** + * The list of instance references to compare to. + */ + const char **instances; + + /** + * The length of @e instances. + */ + unsigned int instances_length; + }; @@ -68,7 +78,6 @@ get_instances_cb (void *cls, unsigned int iis_length, const struct TALER_MERCHANT_InstanceInformation iis[]) { - /* FIXME, deeper checks should be implemented here. */ struct GetInstancesState *gis = cls; gis->igh = NULL; @@ -85,8 +94,67 @@ get_instances_cb (void *cls, switch (hr->http_status) { case MHD_HTTP_OK: - // FIXME: use gis->instance_reference here to - // check if the data returned matches that from the POST / PATCH + if (iis_length != gis->instances_length) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Length of instances found does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + for (unsigned int i = 0; i < iis_length; ++i) + { + const struct TALER_TESTING_Command *instance_cmd; + + instance_cmd = TALER_TESTING_interpreter_lookup_command ( + gis->is, + gis->instances[i]); + + { + const char *name; + if (GNUNET_OK != + TALER_TESTING_get_trait_string (instance_cmd, + 0, + &name)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch instance name\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + if (0 != strcmp (iis[i].name, + name)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Instance name does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + } + + { + const char *id; + if (GNUNET_OK != + TALER_TESTING_get_trait_string (instance_cmd, + 1, + &id)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch instance id\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + if (0 != strcmp (iis[i].id, + id)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Instance id does not match\n"); + TALER_TESTING_interpreter_fail (gis->is); + return; + } + } + } + + // FIXME: compare payment_targets break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -136,9 +204,12 @@ get_instances_cleanup (void *cls, if (NULL != gis->igh) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "GET /instances/$ID operation did not complete\n"); + "GET /instances operation did not complete\n"); TALER_MERCHANT_instances_get_cancel (gis->igh); } + GNUNET_array_grow (gis->instances, + gis->instances_length, + 0); GNUNET_free (gis); } @@ -150,18 +221,35 @@ get_instances_cleanup (void *cls, * @param merchant_url base URL of the merchant serving the * GET /instances 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_instances (const char *label, const char *merchant_url, - unsigned int http_status) + unsigned int http_status, + ...) { struct GetInstancesState *gis; gis = GNUNET_new (struct GetInstancesState); 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->instances, + gis->instances_length, + clabel); + } + va_end (ap); + } { struct TALER_TESTING_Command cmd = { .cls = gis, 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,18 +200,35 @@ 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; gis = GNUNET_new (struct GetProductsState); 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, diff --git a/src/testing/testing_api_cmd_merchant_get_order.c b/src/testing/testing_api_cmd_merchant_get_order.c index 5f148115..985e9116 100644 --- a/src/testing/testing_api_cmd_merchant_get_order.c +++ b/src/testing/testing_api_cmd_merchant_get_order.c @@ -75,6 +75,11 @@ merchant_get_order_cb ( { /* FIXME, deeper checks should be implemented here. */ struct MerchantGetOrderState *gos = cls; + const struct TALER_TESTING_Command *order_cmd; + + order_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->order_reference); gos->ogh = NULL; if (gos->http_status != hr->http_status) diff --git a/src/testing/testing_api_cmd_patch_instance.c b/src/testing/testing_api_cmd_patch_instance.c index 51ffa783..4540bb78 100644 --- a/src/testing/testing_api_cmd_patch_instance.c +++ b/src/testing/testing_api_cmd_patch_instance.c @@ -201,6 +201,7 @@ patch_instance_traits (void *cls, struct PatchInstanceState *pis = cls; struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_string (0, pis->name), + TALER_TESTING_make_trait_string (1, pis->instance_id), TALER_TESTING_make_trait_json (0, pis->address), TALER_TESTING_make_trait_json (1, pis->jurisdiction), TALER_TESTING_make_trait_amount_obj (0, &pis->default_max_wire_fee), diff --git a/src/testing/testing_api_cmd_patch_product.c b/src/testing/testing_api_cmd_patch_product.c index 26088431..a5b5b749 100644 --- a/src/testing/testing_api_cmd_patch_product.c +++ b/src/testing/testing_api_cmd_patch_product.c @@ -209,6 +209,7 @@ patch_product_traits (void *cls, TALER_TESTING_make_trait_int64 (0, &pps->total_stock), TALER_TESTING_make_trait_json (3, pps->address), TALER_TESTING_make_trait_absolute_time (0, &pps->next_restock), + TALER_TESTING_make_trait_string (2, pps->product_id), TALER_TESTING_trait_end (), }; diff --git a/src/testing/testing_api_cmd_post_instances.c b/src/testing/testing_api_cmd_post_instances.c index 22beb10d..e56a3278 100644 --- a/src/testing/testing_api_cmd_post_instances.c +++ b/src/testing/testing_api_cmd_post_instances.c @@ -204,6 +204,7 @@ post_instances_traits (void *cls, struct PostInstancesState *pis = cls; struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_string (0, pis->name), + TALER_TESTING_make_trait_string (1, pis->instance_id), TALER_TESTING_make_trait_json (0, pis->address), TALER_TESTING_make_trait_json (1, pis->jurisdiction), TALER_TESTING_make_trait_amount_obj (0, &pis->default_max_wire_fee), diff --git a/src/testing/testing_api_cmd_post_products.c b/src/testing/testing_api_cmd_post_products.c index 9e78ecbc..671444a4 100644 --- a/src/testing/testing_api_cmd_post_products.c +++ b/src/testing/testing_api_cmd_post_products.c @@ -206,6 +206,7 @@ post_products_traits (void *cls, TALER_TESTING_make_trait_int64 (0, &pps->total_stock), TALER_TESTING_make_trait_json (3, pps->address), TALER_TESTING_make_trait_absolute_time (0, &pps->next_restock), + TALER_TESTING_make_trait_string (2, pps->product_id), TALER_TESTING_trait_end (), }; -- cgit v1.2.3