summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-23 17:08:28 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-23 17:08:28 -0400
commitd34f954dcaf6d064931d47f0c90576f3b1dbf648 (patch)
tree90b74e39bee371213d93286eeb5f8a10dc2c3e28 /src/testing
parentd52356b4ac66bc22f3c7195490ff713668f340b1 (diff)
downloadmerchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.tar.gz
merchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.tar.bz2
merchant-d34f954dcaf6d064931d47f0c90576f3b1dbf648.zip
harder tests for GET /private/instances, GET /private/products
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_merchant_api.c14
-rw-r--r--src/testing/testing_api_cmd_get_instances.c98
-rw-r--r--src/testing/testing_api_cmd_get_products.c74
-rw-r--r--src/testing/testing_api_cmd_merchant_get_order.c5
-rw-r--r--src/testing/testing_api_cmd_patch_instance.c1
-rw-r--r--src/testing/testing_api_cmd_patch_product.c1
-rw-r--r--src/testing/testing_api_cmd_post_instances.c1
-rw-r--r--src/testing/testing_api_cmd_post_products.c1
8 files changed, 181 insertions, 14 deletions
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,12 +221,16 @@ 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;
@@ -163,6 +238,19 @@ TALER_TESTING_cmd_merchant_get_instances (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->instances,
+ gis->instances_length,
+ clabel);
+ }
+ va_end (ap);
+ }
+ {
struct TALER_TESTING_Command cmd = {
.cls = gis,
.label = label,
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,
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 (),
};