gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: allow deleting unclaimed orders


From: gnunet
Subject: [taler-merchant] branch master updated: allow deleting unclaimed orders
Date: Sat, 25 Jul 2020 00:28:53 +0200

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

jonathan-buchanan pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 8631026  allow deleting unclaimed orders
8631026 is described below

commit 8631026e39b5dcd10019b0f770bc79cecf1d6fd5
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Fri Jul 24 18:28:39 2020 -0400

    allow deleting unclaimed orders
---
 src/backenddb/plugin_merchantdb_postgres.c |  7 ++++-
 src/backenddb/test_merchantdb.c            | 41 ++++++++++++++++++++++++------
 src/testing/test_merchant_api.c            |  6 ++++-
 3 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index 3c3eb7a..8d4db04 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -6220,7 +6220,12 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
                             "        FROM merchant_instances"
                             "        WHERE merchant_id=$1)"
                             "   AND merchant_orders.order_id=$2"
-                            "   AND pay_deadline < $3",
+                            "   AND"
+                            "       ((NOT EXISTS"
+                            "        (SELECT order_id"
+                            "           FROM merchant_contract_terms"
+                            "           WHERE 
merchant_contract_terms.order_id=$2))"
+                            "   OR pay_deadline < $3)",
                             3),
     /* for postgres_lookup_order() */
     GNUNET_PQ_make_prepare ("lookup_order",
diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c
index 8206f42..81f66b2 100644
--- a/src/backenddb/test_merchantdb.c
+++ b/src/backenddb/test_merchantdb.c
@@ -1295,18 +1295,16 @@ static void
 make_order (const char *order_id,
             struct OrderData *order)
 {
-  struct GNUNET_TIME_Absolute pay_deadline;
   struct GNUNET_TIME_Absolute refund_deadline;
 
   order->id = order_id;
-  order->pay_deadline = GNUNET_TIME_absolute_get_zero_ ();
   order->contract = json_object ();
   GNUNET_assert (NULL != order->contract);
-  pay_deadline = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
-                                           GNUNET_TIME_UNIT_DAYS);
+  order->pay_deadline = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+                                                  GNUNET_TIME_UNIT_DAYS);
   refund_deadline = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
                                               GNUNET_TIME_UNIT_WEEKS);
-  GNUNET_TIME_round_abs (&pay_deadline);
+  GNUNET_TIME_round_abs (&order->pay_deadline);
   GNUNET_TIME_round_abs (&refund_deadline);
   json_object_set_new (order->contract,
                        "fulfillment_url",
@@ -1316,7 +1314,7 @@ make_order (const char *order_id,
                        json_string (order_id));
   json_object_set_new (order->contract,
                        "pay_deadline",
-                       GNUNET_JSON_from_time_abs (pay_deadline));
+                       GNUNET_JSON_from_time_abs (order->pay_deadline));
   json_object_set_new (order->contract,
                        "refund_deadline",
                        GNUNET_JSON_from_time_abs (refund_deadline));
@@ -1900,7 +1898,7 @@ struct TestOrders_Closure
   /**
    * The array of orders
    */
-  struct OrderData orders[2];
+  struct OrderData orders[3];
 };
 
 
@@ -1925,9 +1923,19 @@ pre_test_orders (struct TestOrders_Closure *cls)
               &cls->orders[0]);
   make_order ("test_orders_od_1",
               &cls->orders[1]);
+  make_order ("test_orders_od_2",
+              &cls->orders[2]);
+
   GNUNET_assert (0 == json_object_set_new (cls->orders[1].contract,
                                            "other_field",
                                            json_string ("Second contract")));
+
+  cls->orders[2].pay_deadline = GNUNET_TIME_UNIT_ZERO_ABS;
+  GNUNET_assert (0 ==
+                 json_object_set_new (
+                   cls->orders[2].contract,
+                   "pay_deadline",
+                   GNUNET_JSON_from_time_abs (cls->orders[2].pay_deadline)));
 }
 
 
@@ -1943,6 +1951,7 @@ post_test_orders (struct TestOrders_Closure *cls)
   free_product_data (&cls->product);
   free_order_data (&cls->orders[0]);
   free_order_data (&cls->orders[1]);
+  free_order_data (&cls->orders[2]);
 }
 
 
@@ -2165,6 +2174,11 @@ run_test_orders (struct TestOrders_Closure *cls)
                                                 true));
   TEST_RET_ON_FAIL (test_mark_order_wired (1007,
                                            
GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
+  /* If an order has been claimed and we aren't past
+     the pay deadline, we can't delete it. */
+  TEST_RET_ON_FAIL (test_delete_order (&cls->instance,
+                                       &cls->orders[0],
+                                       GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
   /* Test deleting contract terms */
   TEST_RET_ON_FAIL (test_delete_contract_terms (&cls->instance,
                                                 &cls->orders[0],
@@ -2173,7 +2187,8 @@ run_test_orders (struct TestOrders_Closure *cls)
   TEST_RET_ON_FAIL (test_delete_contract_terms (&cls->instance,
                                                 &cls->orders[0],
                                                 
GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
-  /* Test delete order */
+  /* Test delete order where we aren't past
+     the deadline, but the order is unclaimed. */
   TEST_RET_ON_FAIL (test_delete_order (&cls->instance,
                                        &cls->orders[1],
                                        GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
@@ -2186,6 +2201,16 @@ run_test_orders (struct TestOrders_Closure *cls)
                                        &cls->orders[1],
                                        GNUNET_DB_STATUS_SUCCESS_NO_RESULTS));
 
+  /* Test we can also delete a claimed order that's past the pay deadline. */
+  TEST_RET_ON_FAIL (test_insert_order (&cls->instance,
+                                       &cls->orders[2],
+                                       GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+  TEST_RET_ON_FAIL (test_insert_contract_terms (&cls->instance,
+                                                &cls->orders[2],
+                                                
GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
+  TEST_RET_ON_FAIL (test_delete_order (&cls->instance,
+                                       &cls->orders[2],
+                                       GNUNET_DB_STATUS_SUCCESS_ONE_RESULT));
   return 0;
 }
 
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 9765b89..067616f 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -206,7 +206,7 @@ run (void *cls,
     TALER_TESTING_cmd_merchant_post_orders_no_claim ("create-proposal-4",
                                                      merchant_url,
                                                      MHD_HTTP_OK,
-                                                     "1",
+                                                     "4",
                                                      GNUNET_TIME_UNIT_ZERO_ABS,
                                                      
GNUNET_TIME_UNIT_FOREVER_ABS,
                                                      "EUR:5.0"),
@@ -216,6 +216,10 @@ run (void *cls,
                                           false,
                                           false,
                                           MHD_HTTP_OK),
+    TALER_TESTING_cmd_merchant_delete_order ("delete-order-4",
+                                             merchant_url,
+                                             "4",
+                                             MHD_HTTP_NO_CONTENT),
     TALER_TESTING_cmd_merchant_purge_instance ("purge-default",
                                                merchant_url,
                                                "default",

-- 
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]