gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] 225/277: stricter tests for query reserve(s) methods


From: gnunet
Subject: [taler-merchant] 225/277: stricter tests for query reserve(s) methods
Date: Sun, 05 Jul 2020 20:52:18 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

commit e35244074480faa18f6370e4d5b800ed35d8ef94
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Fri Jun 19 02:30:17 2020 -0400

    stricter tests for query reserve(s) methods
---
 .../taler-merchant-httpd_private-get-reserves-ID.c |   2 +-
 src/backenddb/plugin_merchantdb_postgres.c         |   3 +-
 src/include/taler_merchant_testing_lib.h           |  36 +++++++
 src/lib/merchant_api_get_reserve.c                 |   4 +-
 src/testing/test_merchant_api.c                    |  15 +++
 src/testing/testing_api_cmd_get_reserve.c          | 114 +++++++++++++++++++++
 src/testing/testing_api_cmd_get_reserves.c         | 102 ++++++++++++++++++
 7 files changed, 272 insertions(+), 4 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-get-reserves-ID.c 
b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
index 2d789d0..7e7c14a 100644
--- a/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
+++ b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c
@@ -94,7 +94,7 @@ handle_reserve_details (void *cls,
       GNUNET_assert (0 ==
                      json_array_append_new (
                        tips_json,
-                       json_pack ("{s:o,s:o,s:I}",
+                       json_pack ("{s:o,s:o,s:s}",
                                   "tip_id",
                                   GNUNET_JSON_from_data_auto (
                                     &tips[i].tip_id),
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 7188839..f218e43 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -4512,7 +4512,8 @@ postgres_lookup_reserve (void *cls,
 {
   struct PostgresClosure *pg = cls;
   struct LookupTipsContext ltc = {
-    .pg = pg
+    .pg = pg,
+    .qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
   };
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_string (instance_id),
diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 85cd73e..02df16c 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -611,6 +611,25 @@ TALER_TESTING_cmd_merchant_get_reserve (const char *label,
                                         const char *reserve_reference);
 
 
+/**
+ * Define a "GET reserve" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the request.
+ * @param http_status expected HTTP response code.
+ * @param reserve_reference reference to a "POST /reserves" that provides the
+ *        information we are expecting.
+ * @param tip_refs a NULL-terminated list of references to tips
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserve_with_tips (const char *label,
+                                                  const char *merchant_url,
+                                                  unsigned int http_status,
+                                                  const char 
*reserve_reference,
+                                                  const char *tip_refs[]);
+
+
 /**
  * Define a "GET /reserves" CMD
  *
@@ -624,6 +643,23 @@ TALER_TESTING_cmd_merchant_get_reserves (const char *label,
                                          unsigned int http_status);
 
 
+/**
+ * Define a "GET /reserves" CMD
+ *
+ * @param label command label.
+ * @param merchant_url url to the merchant.
+ * @param reserve_refs a NULL-terminated list of references to
+ *        commands that created reserves.
+ * @param http_status expected HTTP response code.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label,
+                                                       const char 
*merchant_url,
+                                                       const char *reserve_refs
+                                                       [],
+                                                       unsigned int
+                                                       http_status);
+
 /**
  * Define a "DELETE reserve" CMD.
  *
diff --git a/src/lib/merchant_api_get_reserve.c 
b/src/lib/merchant_api_get_reserve.c
index d9f4a27..f92f37f 100644
--- a/src/lib/merchant_api_get_reserve.c
+++ b/src/lib/merchant_api_get_reserve.c
@@ -155,10 +155,10 @@ handle_reserve_get_finished (void *cls,
         json_array_foreach (tips, i, tip) {
           struct TALER_MERCHANT_TipDetails *td = &tds[i];
           struct GNUNET_JSON_Specification ispec[] = {
-            TALER_JSON_spec_amount ("amount",
-                                    &td->amount),
             GNUNET_JSON_spec_fixed_auto ("tip_id",
                                          &td->tip_id),
+            TALER_JSON_spec_amount ("total_amount",
+                                    &td->amount),
             GNUNET_JSON_spec_string ("reason",
                                      &td->reason),
             GNUNET_JSON_spec_end ()
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 8663b2e..8920a2a 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -49,12 +49,17 @@
  */
 #define EXCHANGE_URL "http://localhost:8081/";
 
+static const char *tip_refs[] = {"authorize-tip-1", "authorize-tip-2", NULL};
+
 static const char *pickup_amounts_1[] = {"EUR:5", NULL};
 
 static const char *pickup_amounts_2[] = {"EUR:0.01", NULL};
 
 static const char *pickup_refs[] = {"pickup-tip-1", "pickup-tip-4", NULL};
 
+static const char *reserve_refs[] = {"create-reserve-tip-1",
+                                     "create-reserve-tip-2", NULL};
+
 /**
  * Payto URI of the customer (payer).
  */
@@ -683,6 +688,11 @@ run (void *cls,
                                             merchant_url,
                                             MHD_HTTP_OK,
                                             "create-reserve-tip-1"),
+    TALER_TESTING_cmd_merchant_get_reserve_with_tips ("get-reserve-2",
+                                                      merchant_url,
+                                                      MHD_HTTP_OK,
+                                                      "create-reserve-tip-1",
+                                                      tip_refs),
     TALER_TESTING_cmd_tip_pickup ("pickup-tip-1",
                                   merchant_url,
                                   MHD_HTTP_OK,
@@ -763,6 +773,11 @@ run (void *cls,
                                           pickup_amounts_1,
                                           TALER_EC_TIP_PICKUP_TIP_ID_UNKNOWN),
 
+    TALER_TESTING_cmd_merchant_get_reserves_with_reserves ("get-reserves-2",
+                                                           merchant_url,
+                                                           reserve_refs,
+                                                           MHD_HTTP_OK),
+
     TALER_TESTING_cmd_merchant_delete_reserve ("delete-reserve-tip-1",
                                                merchant_url,
                                                "create-reserve-tip-1",
diff --git a/src/testing/testing_api_cmd_get_reserve.c 
b/src/testing/testing_api_cmd_get_reserve.c
index 2a685ae..8a26a9a 100644
--- a/src/testing/testing_api_cmd_get_reserve.c
+++ b/src/testing/testing_api_cmd_get_reserve.c
@@ -60,6 +60,11 @@ struct GetReserveState
    * Fetch tips
    */
   bool fetch_tips;
+
+  /**
+   * The list of references to tips.
+   */
+  const char **tip_refs;
 };
 
 
@@ -112,6 +117,76 @@ get_reserve_cb (void *cls,
         return;
       }
     }
+    for (unsigned int i = 0; i < tips_length; ++i)
+    {
+      const struct TALER_TESTING_Command *tip_cmd;
+      if (NULL == grs->tip_refs[i])
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Number of tips authorized does not match\n");
+        TALER_TESTING_interpreter_fail (grs->is);
+        return;
+      }
+
+      tip_cmd = TALER_TESTING_interpreter_lookup_command (grs->is,
+                                                          grs->tip_refs[i]);
+      {
+        const struct GNUNET_HashCode *tip_id;
+
+        if (GNUNET_OK !=
+            TALER_TESTING_get_trait_tip_id (tip_cmd,
+                                            0,
+                                            &tip_id))
+          TALER_TESTING_interpreter_fail (grs->is);
+
+        if (0 != GNUNET_memcmp (&tips[i].tip_id,
+                                tip_id))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Reserve tip id does not match\n");
+          TALER_TESTING_interpreter_fail (grs->is);
+          return;
+        }
+      }
+      {
+        const struct TALER_Amount *total_amount;
+
+        if (GNUNET_OK !=
+            TALER_TESTING_get_trait_amount_obj (tip_cmd,
+                                                0,
+                                                &total_amount))
+          TALER_TESTING_interpreter_fail (grs->is);
+
+        if ((GNUNET_OK != TALER_amount_cmp_currency (&tips[i].amount,
+                                                     total_amount)) ||
+            (0 != TALER_amount_cmp (&tips[i].amount,
+                                    total_amount)))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Reserve tip amount does not match\n");
+          TALER_TESTING_interpreter_fail (grs->is);
+          return;
+        }
+      }
+      {
+        const char *reason;
+
+        if (GNUNET_OK !=
+            TALER_TESTING_get_trait_string (tip_cmd,
+                                            0,
+                                            &reason))
+          TALER_TESTING_interpreter_fail (grs->is);
+
+        if (0 != strcmp (tips[i].reason,
+                         reason))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Reserve tip reason does not match\n");
+          TALER_TESTING_interpreter_fail (grs->is);
+          return;
+        }
+      }
+    }
     break;
   default:
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -217,4 +292,43 @@ TALER_TESTING_cmd_merchant_get_reserve (const char *label,
 }
 
 
+/**
+ * Define a "GET reserve" CMD.
+ *
+ * @param label command label.
+ * @param merchant_url base URL of the merchant serving the request.
+ * @param http_status expected HTTP response code.
+ * @param reserve_reference reference to a "POST /reserves" that provides the
+ *        information we are expecting.
+ * @param tip_refs a NULL-terminated list of references to tips
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserve_with_tips (const char *label,
+                                                  const char *merchant_url,
+                                                  unsigned int http_status,
+                                                  const char 
*reserve_reference,
+                                                  const char *tip_refs[])
+{
+  struct GetReserveState *grs;
+
+  grs = GNUNET_new (struct GetReserveState);
+  grs->merchant_url = merchant_url;
+  grs->http_status = http_status;
+  grs->reserve_reference = reserve_reference;
+  grs->fetch_tips = true;
+  grs->tip_refs = tip_refs;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = grs,
+      .label = label,
+      .run = &get_reserve_run,
+      .cleanup = &get_reserve_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
 /* end of testing_api_cmd_get_reserve.c */
diff --git a/src/testing/testing_api_cmd_get_reserves.c 
b/src/testing/testing_api_cmd_get_reserves.c
index b9909ca..068d7e6 100644
--- a/src/testing/testing_api_cmd_get_reserves.c
+++ b/src/testing/testing_api_cmd_get_reserves.c
@@ -44,6 +44,16 @@ struct GetReservesState
    */
   struct TALER_TESTING_Interpreter *is;
 
+  /**
+   * Whether to compare the reserves that were found.
+   */
+  bool cmp_reserves;
+
+  /**
+   * A list of reserves to compare with.
+   */
+  const char **reserve_refs;
+
   /**
    * Base URL of the merchant serving the request.
    */
@@ -80,6 +90,61 @@ get_reserves_cb (void *cls,
   {
   case MHD_HTTP_OK:
     // FIXME: check if the data returned matches that from the POST / PATCH
+    if (! grs->cmp_reserves)
+      break;
+    for (unsigned int i = 0; i < reserves_length; ++i)
+    {
+      if (NULL == grs->reserve_refs[i])
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Number of reserves found does not match\n");
+        TALER_TESTING_interpreter_fail (grs->is);
+        return;
+      }
+
+      const struct TALER_TESTING_Command *reserve_cmd;
+
+      reserve_cmd = TALER_TESTING_interpreter_lookup_command (
+        grs->is,
+        grs->reserve_refs[i]);
+      {
+        const struct TALER_ReservePublicKeyP *reserve_pub;
+
+        if (GNUNET_OK !=
+            TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
+                                                 0,
+                                                 &reserve_pub))
+          TALER_TESTING_interpreter_fail (grs->is);
+        if (0 != GNUNET_memcmp (&reserves[i].reserve_pub,
+                                reserve_pub))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Reserve public key does not match\n");
+          TALER_TESTING_interpreter_fail (grs->is);
+          return;
+        }
+      }
+      {
+        const struct TALER_Amount *initial;
+
+        if (GNUNET_OK !=
+            TALER_TESTING_get_trait_amount_obj (reserve_cmd,
+                                                0,
+                                                &initial))
+          TALER_TESTING_interpreter_fail (grs->is);
+        if ((GNUNET_OK != TALER_amount_cmp_currency (
+               &reserves[i].merchant_initial_amount,
+               initial)) ||
+            (0 != TALER_amount_cmp (&reserves[i].merchant_initial_amount,
+                                    initial)))
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Reserve initial amount does not match\n");
+          TALER_TESTING_interpreter_fail (grs->is);
+          return;
+        }
+      }
+    }
     break;
   default:
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -155,6 +220,43 @@ TALER_TESTING_cmd_merchant_get_reserves (const char *label,
 
   grs = GNUNET_new (struct GetReservesState);
   grs->merchant_url = merchant_url;
+  grs->cmp_reserves = false;
+  grs->http_status = http_status;
+  {
+    struct TALER_TESTING_Command cmd = {
+      .cls = grs,
+      .label = label,
+      .run = &get_reserves_run,
+      .cleanup = &get_reserves_cleanup
+    };
+
+    return cmd;
+  }
+}
+
+
+/**
+ * Define a "GET /reserves" CMD
+ *
+ * @param label command label.
+ * @param merchant_url url to the merchant.
+ * @param reserve_refs a NULL-terminated list of references to
+ *        commands that created reserves.
+ * @param http_status expected HTTP response code.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_merchant_get_reserves_with_reserves (const char *label,
+                                                       const char 
*merchant_url,
+                                                       const char *reserve_refs
+                                                       [],
+                                                       unsigned int 
http_status)
+{
+  struct GetReservesState *grs;
+
+  grs = GNUNET_new (struct GetReservesState);
+  grs->merchant_url = merchant_url;
+  grs->cmp_reserves = true;
+  grs->reserve_refs = reserve_refs;
   grs->http_status = http_status;
   {
     struct TALER_TESTING_Command cmd = {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]