summaryrefslogtreecommitdiff
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
parentd83304e2a3af18480e3c83077c54a1b532904d2b (diff)
downloadmerchant-cac09657404fa6075fad0e09b6a855b4110f792d.tar.gz
merchant-cac09657404fa6075fad0e09b6a855b4110f792d.tar.bz2
merchant-cac09657404fa6075fad0e09b6a855b4110f792d.zip
more checks for GET /private/products/
-rw-r--r--src/include/taler_merchant_testing_lib.h56
-rw-r--r--src/testing/Makefile.am1
-rw-r--r--src/testing/test_merchant_api.c9
-rw-r--r--src/testing/testing_api_cmd_get_instance.c12
-rw-r--r--src/testing/testing_api_cmd_get_product.c155
-rw-r--r--src/testing/testing_api_cmd_patch_instance.c4
-rw-r--r--src/testing/testing_api_cmd_patch_product.c40
-rw-r--r--src/testing/testing_api_cmd_post_instances.c4
-rw-r--r--src/testing/testing_api_cmd_post_products.c40
-rw-r--r--src/testing/testing_api_trait_merchant_json.c114
10 files changed, 247 insertions, 188 deletions
diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h
index ff9f785d..352f39c3 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1260,62 +1260,6 @@ TALER_TESTING_get_trait_merchant_sig (
/**
- * Obtain merchant address from @a cmd.
- *
- * @param cmd command to extract the address from.
- * @param index index number associate with the address on offer.
- * @param[out] address where to write the address.
- * @return #GNUNET_OK on success.
- */
-int
-TALER_TESTING_get_trait_merchant_address (const struct
- TALER_TESTING_Command *cmd,
- unsigned int index,
- const json_t **address);
-
-
-/**
- * Offer merchant address in a trait.
- *
- * @param index index number associate with the address
- * on offer.
- * @param address address to offer.
- * @return the trait.
- */
-struct TALER_TESTING_Trait
-TALER_TESTING_make_trait_merchant_address (unsigned int index,
- const json_t *address);
-
-
-/**
- * Obtain merchant jurisdiction from @a cmd.
- *
- * @param cmd command to extract the jurisdiction from.
- * @param index index number associate with the jurisdiction on offer.
- * @param[out] jurisdiction where to write the jurisdiction.
- * @return #GNUNET_OK on success.
- */
-int
-TALER_TESTING_get_trait_merchant_jurisdiction (const struct
- TALER_TESTING_Command *cmd,
- unsigned int index,
- const json_t **jurisdiction);
-
-
-/**
- * Offer merchant jurisdiction in a trait.
- *
- * @param index index number associate with the jurisdiction
- * on offer.
- * @param jurisdiction jurisdiction to offer.
- * @return the trait.
- */
-struct TALER_TESTING_Trait
-TALER_TESTING_make_trait_merchant_jurisdiction (unsigned int index,
- const json_t *jurisdiction);
-
-
-/**
* Obtain a reference to a proposal command. Any command that
* works with proposals, might need to offer their reference to
* it. Notably, the "pay" command, offers its proposal reference
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 8a41ae30..228113df 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -53,7 +53,6 @@ libtalermerchanttesting_la_SOURCES = \
testing_api_trait_merchant_sig.c \
testing_api_trait_string.c \
testing_api_trait_hash.c \
- testing_api_trait_merchant_json.c \
testing_api_trait_planchet.c \
testing_api_trait_refund_entry.c
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 9362be38..224a8076 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -1066,6 +1066,11 @@ run (void *cls,
GNUNET_TIME_relative_to_absolute (
GNUNET_TIME_UNIT_MINUTES),
MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_merchant_get_product ("get-product-p2",
+ merchant_url,
+ "product-2",
+ MHD_HTTP_OK,
+ "patch-products-p2"),
TALER_TESTING_cmd_merchant_patch_product ("patch-products-p3-nx",
merchant_url,
"product-3",
@@ -1111,10 +1116,10 @@ run (void *cls,
10),
TALER_TESTING_cmd_batch ("refund",
refund),
-#endif
+// #endif
TALER_TESTING_cmd_batch ("tip",
tip),
-#if 0
+// #if 0
TALER_TESTING_cmd_batch ("pay-again",
pay_again),
TALER_TESTING_cmd_batch ("pay-abort",
diff --git a/src/testing/testing_api_cmd_get_instance.c b/src/testing/testing_api_cmd_get_instance.c
index a5896659..c48182eb 100644
--- a/src/testing/testing_api_cmd_get_instance.c
+++ b/src/testing/testing_api_cmd_get_instance.c
@@ -120,9 +120,9 @@ get_instance_cb (void *cls,
{
const struct json_t *address;
if (GNUNET_OK !=
- TALER_TESTING_get_trait_merchant_address (instance_cmd,
- 0,
- &address))
+ TALER_TESTING_get_trait_json (instance_cmd,
+ 0,
+ &address))
TALER_TESTING_interpreter_fail (gis->is);
if (1 != json_equal (details->address,
address))
@@ -136,9 +136,9 @@ get_instance_cb (void *cls,
{
const struct json_t *jurisdiction;
if (GNUNET_OK !=
- TALER_TESTING_get_trait_merchant_jurisdiction (instance_cmd,
- 0,
- &jurisdiction))
+ TALER_TESTING_get_trait_json (instance_cmd,
+ 1,
+ &jurisdiction))
TALER_TESTING_interpreter_fail (gis->is);
if (1 != json_equal (details->jurisdiction,
jurisdiction))
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,
diff --git a/src/testing/testing_api_cmd_patch_instance.c b/src/testing/testing_api_cmd_patch_instance.c
index cb547ff4..51ffa783 100644
--- a/src/testing/testing_api_cmd_patch_instance.c
+++ b/src/testing/testing_api_cmd_patch_instance.c
@@ -201,8 +201,8 @@ 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_merchant_address (0, pis->address),
- TALER_TESTING_make_trait_merchant_jurisdiction (0, pis->jurisdiction),
+ 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),
TALER_TESTING_make_trait_uint32 (0, &pis->default_wire_fee_amortization),
TALER_TESTING_make_trait_amount_obj (1, &pis->default_max_deposit_fee),
diff --git a/src/testing/testing_api_cmd_patch_product.c b/src/testing/testing_api_cmd_patch_product.c
index 9ddcdceb..26088431 100644
--- a/src/testing/testing_api_cmd_patch_product.c
+++ b/src/testing/testing_api_cmd_patch_product.c
@@ -183,6 +183,43 @@ patch_product_run (void *cls,
/**
+ * Offers information from the PATCH /products CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+patch_product_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PatchProductState *pps = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_string (0, pps->description),
+ TALER_TESTING_make_trait_json (0, pps->description_i18n),
+ TALER_TESTING_make_trait_string (1, pps->unit),
+ TALER_TESTING_make_trait_amount_obj (0, &pps->price),
+ TALER_TESTING_make_trait_json (1, pps->image),
+ TALER_TESTING_make_trait_json (2, pps->taxes),
+ 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_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
* Free the state of a "GET product" CMD, and possibly
* cancel a pending operation thereof.
*
@@ -274,7 +311,8 @@ TALER_TESTING_cmd_merchant_patch_product (
.cls = pis,
.label = label,
.run = &patch_product_run,
- .cleanup = &patch_product_cleanup
+ .cleanup = &patch_product_cleanup,
+ .traits = &patch_product_traits
};
return cmd;
diff --git a/src/testing/testing_api_cmd_post_instances.c b/src/testing/testing_api_cmd_post_instances.c
index 55a27841..22beb10d 100644
--- a/src/testing/testing_api_cmd_post_instances.c
+++ b/src/testing/testing_api_cmd_post_instances.c
@@ -204,8 +204,8 @@ 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_merchant_address (0, pis->address),
- TALER_TESTING_make_trait_merchant_jurisdiction (0, pis->jurisdiction),
+ 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),
TALER_TESTING_make_trait_uint32 (0, &pis->default_wire_fee_amortization),
TALER_TESTING_make_trait_amount_obj (1, &pis->default_max_deposit_fee),
diff --git a/src/testing/testing_api_cmd_post_products.c b/src/testing/testing_api_cmd_post_products.c
index 68f68972..9e78ecbc 100644
--- a/src/testing/testing_api_cmd_post_products.c
+++ b/src/testing/testing_api_cmd_post_products.c
@@ -180,6 +180,43 @@ post_products_run (void *cls,
/**
+ * Offers information from the POST /products CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param ret[out] result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to extract.
+ * @return #GNUNET_OK on success
+ */
+static int
+post_products_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct PostProductsState *pps = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_string (0, pps->description),
+ TALER_TESTING_make_trait_json (0, pps->description_i18n),
+ TALER_TESTING_make_trait_string (1, pps->unit),
+ TALER_TESTING_make_trait_amount_obj (0, &pps->price),
+ TALER_TESTING_make_trait_json (1, pps->image),
+ TALER_TESTING_make_trait_json (2, pps->taxes),
+ 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_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
* Free the state of a "POST product" CMD, and possibly
* cancel a pending operation thereof.
*
@@ -267,7 +304,8 @@ TALER_TESTING_cmd_merchant_post_products2 (
.cls = pis,
.label = label,
.run = &post_products_run,
- .cleanup = &post_products_cleanup
+ .cleanup = &post_products_cleanup,
+ .traits = &post_products_traits
};
return cmd;
diff --git a/src/testing/testing_api_trait_merchant_json.c b/src/testing/testing_api_trait_merchant_json.c
deleted file mode 100644
index 8caa5c11..00000000
--- a/src/testing/testing_api_trait_merchant_json.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/testing_api_trait_merchant_json.c
- * @brief offer merchant address and jurisdiction
- * @author Jonathan Buchanan
- */
-#include "platform.h"
-#include <taler/taler_signatures.h>
-#include <taler/taler_exchange_service.h>
-#include <taler/taler_testing_lib.h>
-
-#define TALER_TESTING_TRAIT_MERCHANT_ADDRESS "merchant-address"
-#define TALER_TESTING_TRAIT_MERCHANT_JURISDICTION "merchant_jurisdiction"
-
-
-/**
- * Obtain merchant address from @a cmd.
- *
- * @param cmd command to extract the address from.
- * @param index index number associate with the address on offer.
- * @param[out] address where to write the address.
- * @return #GNUNET_OK on success.
- */
-int
-TALER_TESTING_get_trait_merchant_address (const struct
- TALER_TESTING_Command *cmd,
- unsigned int index,
- const json_t **address)
-{
- return cmd->traits (cmd->cls,
- (const void **) address,
- TALER_TESTING_TRAIT_MERCHANT_ADDRESS,
- index);
-}
-
-
-/**
- * Offer merchant address in a trait.
- *
- * @param index index number associate with the address
- * on offer.
- * @param address address to offer.
- * @return the trait.
- */
-struct TALER_TESTING_Trait
-TALER_TESTING_make_trait_merchant_address (unsigned int index,
- const json_t *address)
-{
- struct TALER_TESTING_Trait ret = {
- .index = index,
- .trait_name = TALER_TESTING_TRAIT_MERCHANT_ADDRESS,
- .ptr = (const void *) address
- };
- return ret;
-}
-
-
-/**
- * Obtain merchant jurisdiction from @a cmd.
- *
- * @param cmd command to extract the jurisdiction from.
- * @param index index number associate with the jurisdiction on offer.
- * @param[out] jurisdiction where to write the jurisdiction.
- * @return #GNUNET_OK on success.
- */
-int
-TALER_TESTING_get_trait_merchant_jurisdiction (const struct
- TALER_TESTING_Command *cmd,
- unsigned int index,
- const json_t **jurisdiction)
-{
- return cmd->traits (cmd->cls,
- (const void **) jurisdiction,
- TALER_TESTING_TRAIT_MERCHANT_JURISDICTION,
- index);
-}
-
-
-/**
- * Offer merchant jurisdiction in a trait.
- *
- * @param index index number associate with the jurisdiction
- * on offer.
- * @param jurisdiction jurisdiction to offer.
- * @return the trait.
- */
-struct TALER_TESTING_Trait
-TALER_TESTING_make_trait_merchant_jurisdiction (unsigned int index,
- const json_t *jurisdiction)
-{
- struct TALER_TESTING_Trait ret = {
- .index = index,
- .trait_name = TALER_TESTING_TRAIT_MERCHANT_JURISDICTION,
- .ptr = (const void *) jurisdiction
- };
- return ret;
-}