From 847a9d6f54080bf852ef89a0d2fa4eb419272a5f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 20 Apr 2021 18:25:48 -0300 Subject: cannot increase stock if the product has an order asociated --- src/testing/test_merchant_order_creation.sh | 24 +----- src/testing/test_merchant_product_creation.sh | 111 ++++++++++++++++++++++++-- 2 files changed, 108 insertions(+), 27 deletions(-) (limited to 'src/testing') diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh index f08122d8..9e3e0d09 100755 --- a/src/testing/test_merchant_order_creation.sh +++ b/src/testing/test_merchant_order_creation.sh @@ -295,26 +295,10 @@ BALANCE=`jq -r .balance.amount < $LAST_RESPONSE` if [ "$BALANCE" == "TESTKUDOS:0" ] then - echo 'wire transfer did not happen. got:' $BALANCE - echo 'going to sleep more, just in case...' - sleep 62 - - STATUS=$(curl "http://$ACCOUNT_PASSWORD@$BANK_HOST/accounts/43" \ - -w "%{http_code}" -s -o $LAST_RESPONSE) - - if [ "$STATUS" != "200" ] - then - echo 'should response ok, getting account status. got:' $STATUS `cat $LAST_RESPONSE` - exit 1 - fi - - BALANCE=`jq -r .balance.amount < $LAST_RESPONSE` - - if [ "$BALANCE" == "TESTKUDOS:0" ] - then - echo 'wire transfer did not happend. got:' $BALANCE `cat $LAST_RESPONSE` - exit 1 - fi + echo 'wire transfer did not happend. got:' $BALANCE `cat $LAST_RESPONSE` + exit 1 fi + + exit 0 diff --git a/src/testing/test_merchant_product_creation.sh b/src/testing/test_merchant_product_creation.sh index cbfdb6c8..defbcb37 100755 --- a/src/testing/test_merchant_product_creation.sh +++ b/src/testing/test_merchant_product_creation.sh @@ -18,13 +18,22 @@ fi echo OK RANDOM_IMG='data:image/png;base64,abcdefg' -INFINITE_PRODUCT_TEMPLATE='{"product_id":"2","description":"product with id 2 and price :15","price":"TESTKUDOS:15","total_stock":-1,"description_i18n":{},"unit":"","image":"'$RANDOM_IMG'","taxes":[]}' +INFINITE_PRODUCT_TEMPLATE='{"product_id":"2","description":"product with id 2 and price :15","price":"TESTKUDOS:15","total_stock":-1,"unit":"","image":"'$RANDOM_IMG'","taxes":[]}' +MANAGED_PRODUCT_TEMPLATE='{"product_id":"3","description":"product with id 3 and price :10","price":"TESTKUDOS:150","total_stock":2,"unit":"","image":"'$RANDOM_IMG'","taxes":[]}' -PRODUCT_DATA=$INFINITE_PRODUCT_TEMPLATE +echo -n "Creating products..." +STATUS=$(curl 'http://localhost:9966/instances/default/private/products' \ + -d "$INFINITE_PRODUCT_TEMPLATE" \ + -w "%{http_code}" -s -o /dev/null) + +if [ "$STATUS" != "204" ] +then + echo 'should respond ok, product created. got:' $STATUS + exit 1 +fi -echo -n "Creating product..." STATUS=$(curl 'http://localhost:9966/instances/default/private/products' \ - -d "$PRODUCT_DATA" \ + -d "$MANAGED_PRODUCT_TEMPLATE" \ -w "%{http_code}" -s -o /dev/null) if [ "$STATUS" != "204" ] @@ -34,10 +43,10 @@ then fi echo OK -PRODUCT_DATA=$(echo $PRODUCT_DATA | jq 'del(.product_id)') -PRODUCT_DATA=$(echo $PRODUCT_DATA | jq '. + {description: "other description"}') -echo -n "Updating product..." +PRODUCT_DATA=$(echo $INFINITE_PRODUCT_TEMPLATE | jq 'del(.product_id) | . + {description: "other description"}') + +echo -n "Updating infinite stock product..." STATUS=$(curl 'http://localhost:9966/instances/default/private/products/2' -X PATCH \ -d "$PRODUCT_DATA" \ -w "%{http_code}" -s -o $LAST_RESPONSE) @@ -63,4 +72,92 @@ 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}]}' \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "200" ] +then + echo 'should response ok, order created. got:' $STATUS `cat $LAST_RESPONSE` + exit 1 +fi + +ORDER_ID=`jq -e -r .order_id < $LAST_RESPONSE` +TOKEN=`jq -e -r .token < $LAST_RESPONSE` + +STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "200" ] +then + echo 'should response 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 "First withdraw wallet" +rm $WALLET_DB +taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'withdrawTestBalance' \ + "$(jq -n ' + { + amount: "TESTKUDOS:5", + bankBaseUrl: $BANK_URL, + exchangeBaseUrl: $EXCHANGE_URL + }' \ + --arg BANK_URL "$BANK_URL" \ + --arg EXCHANGE_URL "$EXCHANGE_URL" + )" 2>wallet-withdraw-1.err >wallet-withdraw-1.out +taler-wallet-cli --wallet-db=$WALLET_DB run-until-done 2>wallet-withdraw-finish-1.err >wallet-withdraw-finish-1.out +echo " OK" + +NOW=`date +%s` + +echo -n "Pay first order ..." +taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB handle-uri "${PAY_URL}" -y 2> wallet-pay1.err > wallet-pay1.log +NOW2=`date +%s` +echo " OK (took $( echo -n $(($NOW2 - $NOW)) ) secs )" + + +STATUS=$(curl "http://localhost:9966/instances/default/private/orders/${ORDER_ID}" \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "200" ] +then + echo 'should response ok, after pay. got:' $STATUS `cat $LAST_RESPONSE` + exit 1 +fi + +ORDER_STATUS=`jq -r .order_status < $LAST_RESPONSE` + +if [ "$ORDER_STATUS" != "paid" ] +then + echo 'order should be paid. got:' $ORDER_STATUS `cat $LAST_RESPONSE` + exit 1 +fi + + +echo -n "Updating product..." + +PRODUCT_DATA=$(echo $MANAGED_PRODUCT_TEMPLATE | jq 'del(.product_id) | . + {"total_stock": (.total_stock + 2) }') + +STATUS=$(curl 'http://localhost:9966/instances/default/private/products/2' -X PATCH \ + -d "$PRODUCT_DATA" \ + -w "%{http_code}" -s -o $LAST_RESPONSE) + +if [ "$STATUS" != "204" ] +then + echo 'should respond ok, updating product. got:' $STATUS + cat $LAST_RESPONSE + exit 1 +fi + +echo " OK" + exit 0 -- cgit v1.2.3