summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-24 18:28:39 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-07-24 18:28:39 -0400
commit8631026e39b5dcd10019b0f770bc79cecf1d6fd5 (patch)
treeeb6413bdaf88f0ca16430ca4b1f557a9e8b55802 /src/backenddb
parent31b17ff2582bbc6890b829ef4746aa0d37b6d9d9 (diff)
downloadmerchant-8631026e39b5dcd10019b0f770bc79cecf1d6fd5.tar.gz
merchant-8631026e39b5dcd10019b0f770bc79cecf1d6fd5.tar.bz2
merchant-8631026e39b5dcd10019b0f770bc79cecf1d6fd5.zip
allow deleting unclaimed orders
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c7
-rw-r--r--src/backenddb/test_merchantdb.c41
2 files changed, 39 insertions, 9 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 3c3eb7a6..8d4db04b 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 8206f421..81f66b25 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;
}