summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing')
-rwxr-xr-xsrc/testing/test_merchant_product_creation.sh68
-rw-r--r--src/testing/testing_api_cmd_lock_product.c12
-rw-r--r--src/testing/testing_api_cmd_post_orders.c14
3 files changed, 75 insertions, 19 deletions
diff --git a/src/testing/test_merchant_product_creation.sh b/src/testing/test_merchant_product_creation.sh
index 938a13d3..78b95d4e 100755
--- a/src/testing/test_merchant_product_creation.sh
+++ b/src/testing/test_merchant_product_creation.sh
@@ -85,20 +85,47 @@ then
cat $LAST_RESPONSE
exit 1
fi
-
echo OK
+MANAGED_PRODUCT_ID=$(echo $MANAGED_PRODUCT_TEMPLATE | jq -r '.product_id')
+
+echo -n "Locking inventory ..."
+
+STATUS=$(curl "http://localhost:9966/instances/default/private/products/${MANAGED_PRODUCT_ID}/lock" \
+ -d '{"lock_uuid":"luck","duration":{"d_ms": 100000},"quantity":10}' \
+ -w "%{http_code}" -s -o $LAST_RESPONSE)
+
+if [ "$STATUS" != "410" ]
+then
+ echo 'should respond gone, lock failed. got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+fi
+
+echo -n "."
+
+STATUS=$(curl "http://localhost:9966/instances/default/private/products/${MANAGED_PRODUCT_ID}/lock" \
+ -d '{"lock_uuid":"luck","duration":{"d_ms": 100000},"quantity":1}' \
+ -w "%{http_code}" -s -o $LAST_RESPONSE)
+
+if [ "$STATUS" != "204" ]
+then
+ echo 'should respond ok, lock created. got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+fi
+
+echo " OK"
+
+
echo -n "Creating order to be paid..."
-MANAGED_PRODUCT_ID=$(echo $MANAGED_PRODUCT_TEMPLATE | jq -r '.product_id')
STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \
- -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"inventory_products":[{"product_id":"'$MANAGED_PRODUCT_ID'","quantity":1}]}' \
+ -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"inventory_products":[{"product_id":"'${MANAGED_PRODUCT_ID}'","quantity":1}]}' \
-w "%{http_code}" -s -o $LAST_RESPONSE)
if [ "$STATUS" != "200" ]
then
- echo 'should response ok, order created. got:' $STATUS `cat $LAST_RESPONSE`
+ echo 'should respond ok, order created. got:' $STATUS `cat $LAST_RESPONSE`
exit 1
fi
@@ -110,13 +137,38 @@ STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID
if [ "$STATUS" != "200" ]
then
- echo 'should response ok, getting order info before claming it. got:' $STATUS `cat $LAST_RESPONSE`
+ echo 'should respond ok, getting order info before claming it. got:' $STATUS `cat $LAST_RESPONSE`
exit 1
fi
-
PAY_URL=`jq -e -r .taler_pay_uri < $LAST_RESPONSE`
-echo OK
+echo -n "."
+
+STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \
+ -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"inventory_products":[{"product_id":"'${MANAGED_PRODUCT_ID}'","quantity":1}]}' \
+ -w "%{http_code}" -s -o $LAST_RESPONSE)
+
+if [ "$STATUS" != "410" ]
+then
+ echo 'should respond out of stock (what remains is locked). got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+fi
+
+echo -n "."
+
+# Using the 'luck' inventory lock, order creation should work.
+STATUS=$(curl 'http://localhost:9966/instances/default/private/orders' \
+ -d '{"order":{"amount":"TESTKUDOS:1","summary":"payme"},"lock_uuids":["luck"],"inventory_products":[{"product_id":"'$MANAGED_PRODUCT_ID'","quantity":1}]}' \
+ -w "%{http_code}" -s -o $LAST_RESPONSE)
+
+if [ "$STATUS" != "200" ]
+then
+ echo 'should respond ok, lock should apply. got:' $STATUS `cat $LAST_RESPONSE`
+ exit 1
+fi
+
+
+echo " OK"
echo -n "First withdraw wallet"
rm $WALLET_DB
@@ -146,7 +198,7 @@ STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID
if [ "$STATUS" != "200" ]
then
- echo 'should response ok, after pay. got:' $STATUS `cat $LAST_RESPONSE`
+ echo 'should respond ok, after pay. got:' $STATUS `cat $LAST_RESPONSE`
exit 1
fi
diff --git a/src/testing/testing_api_cmd_lock_product.c b/src/testing/testing_api_cmd_lock_product.c
index abb5920c..49f815d6 100644
--- a/src/testing/testing_api_cmd_lock_product.c
+++ b/src/testing/testing_api_cmd_lock_product.c
@@ -57,7 +57,7 @@ struct LockProductState
/**
* UUID that identifies the client holding the lock
*/
- struct GNUNET_Uuid uuid;
+ char *uuid;
/**
* duration how long should the lock be held
@@ -138,7 +138,7 @@ lock_product_run (void *cls,
pis->iph = TALER_MERCHANT_product_lock (is->ctx,
pis->merchant_url,
pis->product_id,
- &pis->uuid,
+ pis->uuid,
pis->duration,
pis->quantity,
&lock_product_cb,
@@ -166,6 +166,7 @@ lock_product_cleanup (void *cls,
"POST /product/$ID/lock operation did not complete\n");
TALER_MERCHANT_product_lock_cancel (pis->iph);
}
+ GNUNET_free (pis->uuid);
GNUNET_free (pis);
}
@@ -188,7 +189,7 @@ lock_product_traits (void *cls,
struct LockProductState *lps = cls;
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_uuid (0, &lps->uuid),
+ TALER_TESTING_make_trait_string (0, lps->uuid),
TALER_TESTING_trait_end ()
};
@@ -209,14 +210,17 @@ TALER_TESTING_cmd_merchant_lock_product (
unsigned int http_status)
{
struct LockProductState *pis;
+ struct GNUNET_Uuid uuid;
pis = GNUNET_new (struct LockProductState);
pis->merchant_url = merchant_url;
pis->product_id = product_id;
pis->http_status = http_status;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
- &pis->uuid,
+ &uuid,
sizeof (struct GNUNET_Uuid));
+ pis->uuid = GNUNET_STRINGS_data_to_string_alloc (&uuid,
+ sizeof (uuid));
pis->duration = duration;
pis->quantity = quantity;
diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c
index 5b9e533f..f7c00388 100644
--- a/src/testing/testing_api_cmd_post_orders.c
+++ b/src/testing/testing_api_cmd_post_orders.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2018 Taler Systems SA
+ Copyright (C) 2014-2021 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
@@ -439,7 +439,7 @@ orders_run2 (void *cls,
char *token;
struct TALER_MERCHANT_InventoryProduct *products = NULL;
unsigned int products_length = 0;
- struct GNUNET_Uuid *locks = NULL;
+ const char **locks = NULL;
unsigned int locks_length = 0;
ps->is = is;
@@ -527,16 +527,16 @@ orders_run2 (void *cls,
token = strtok (NULL, ";"))
{
const struct TALER_TESTING_Command *lock_cmd;
- struct GNUNET_Uuid *uuid;
+ const char *uuid;
lock_cmd = TALER_TESTING_interpreter_lookup_command (
is,
token);
if (GNUNET_OK !=
- TALER_TESTING_get_trait_uuid (lock_cmd,
- 0,
- &uuid))
+ TALER_TESTING_get_trait_string (lock_cmd,
+ 0,
+ &uuid))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not fetch lock uuid\n");
@@ -546,7 +546,7 @@ orders_run2 (void *cls,
GNUNET_array_append (locks,
locks_length,
- *uuid);
+ uuid);
}
ps->po = TALER_MERCHANT_orders_post2 (is->ctx,
ps->merchant_url,