summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_get_product.c
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-22 16:34:21 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-22 16:34:21 -0400
commitcac09657404fa6075fad0e09b6a855b4110f792d (patch)
tree8a62808678143e4aa0fee6ef858364a6a0a67aaf /src/testing/testing_api_cmd_get_product.c
parentd83304e2a3af18480e3c83077c54a1b532904d2b (diff)
downloadmerchant-cac09657404fa6075fad0e09b6a855b4110f792d.tar.gz
merchant-cac09657404fa6075fad0e09b6a855b4110f792d.tar.bz2
merchant-cac09657404fa6075fad0e09b6a855b4110f792d.zip
more checks for GET /private/products/
Diffstat (limited to 'src/testing/testing_api_cmd_get_product.c')
-rw-r--r--src/testing/testing_api_cmd_get_product.c155
1 files changed, 152 insertions, 3 deletions
diff --git a/src/testing/testing_api_cmd_get_product.c b/src/testing/testing_api_cmd_get_product.c
index 8ba63af6..72211c45 100644
--- a/src/testing/testing_api_cmd_get_product.c
+++ b/src/testing/testing_api_cmd_get_product.c
@@ -106,8 +106,12 @@ get_product_cb (void *cls,
const json_t *location,
struct GNUNET_TIME_Absolute next_restock)
{
- /* FIXME, deeper checks should be implemented here. */
struct GetProductState *gis = cls;
+ const struct TALER_TESTING_Command *product_cmd;
+
+ product_cmd = TALER_TESTING_interpreter_lookup_command (
+ gis->is,
+ gis->product_reference);
gis->igh = NULL;
if (gis->http_status != hr->http_status)
@@ -123,8 +127,153 @@ get_product_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
+ {
+ const char *expected_description;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_string (product_cmd,
+ 0,
+ &expected_description))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (description,
+ expected_description))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product description does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const json_t *expected_description_i18n;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_json (product_cmd,
+ 0,
+ &expected_description_i18n))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (1 != json_equal (description_i18n,
+ expected_description_i18n))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product description i18n does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const struct TALER_Amount *expected_price;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount_obj (product_cmd,
+ 0,
+ &expected_price))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if ((GNUNET_OK != TALER_amount_cmp_currency (price,
+ expected_price)) ||
+ (0 != TALER_amount_cmp (price,
+ expected_price)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product price does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const json_t *expected_image;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_json (product_cmd,
+ 1,
+ &expected_image))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (1 != json_equal (image,
+ expected_image))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product image does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const json_t *expected_taxes;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_json (product_cmd,
+ 2,
+ &expected_taxes))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (1 != json_equal (taxes,
+ expected_taxes))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product taxes do not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const char *expected_unit;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_string (product_cmd,
+ 1,
+ &expected_unit))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (0 != strcmp (unit,
+ expected_unit))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product unit does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const json_t *expected_location;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_json (product_cmd,
+ 3,
+ &expected_location))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (1 != json_equal (location,
+ expected_location))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product location does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const int64_t *expected_total_stock;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_int64 (product_cmd,
+ 0,
+ &expected_total_stock))
+ TALER_TESTING_interpreter_fail (gis->is);
+ if (total_stock != *expected_total_stock)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product total stock does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
+ {
+ const struct GNUNET_TIME_Absolute *expected_next_restock;
+ struct GNUNET_TIME_Absolute expected_next_restock_round;
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_absolute_time (product_cmd,
+ 0,
+ &expected_next_restock))
+ TALER_TESTING_interpreter_fail (gis->is);
+ expected_next_restock_round = *expected_next_restock;
+ GNUNET_TIME_round_abs (&expected_next_restock_round);
+ if (next_restock.abs_value_us != expected_next_restock_round.abs_value_us)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Product next restock does not match\n");
+ TALER_TESTING_interpreter_fail (gis->is);
+ return;
+ }
+ }
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,