From b243c4d358fc415d2dd5ace9fd25750f65316d2c Mon Sep 17 00:00:00 2001 From: Christian Blättler Date: Mon, 15 Apr 2024 19:46:19 +0200 Subject: add test for order creation with v1 contract --- src/testing/test_merchant_order_creation.sh | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/testing/test_merchant_order_creation.sh') diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh index 175667b9..bf1c5d02 100755 --- a/src/testing/test_merchant_order_creation.sh +++ b/src/testing/test_merchant_order_creation.sh @@ -243,6 +243,46 @@ then fi echo "OK" +# +# CREATE TOKEN FAMILY AND V1 ORDER WITH CHOICES +# +echo -n "Creating token family..." +NOW=$(date +%s) +IN_A_YEAR=$((NOW + 31536000)) +STATUS=$(curl 'http://localhost:9966/private/tokenfamilies' \ + -d '{"slug":"test-sub","kind":"subscription","description":"Test token family","name":"Test Subscription","valid_after":{"t_s":'$NOW'},"valid_before":{"t_s":'$IN_A_YEAR'},"duration": {"d_us": 2592000000}}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") + +if [ "$STATUS" != "204" ] +then + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected 204, token family created. got: $STATUS" +fi + +echo -n "Creating v1 order with token family..." +STATUS=$(curl 'http://localhost:9966/private/orders' \ + -d '{"order":{"version":"1","amount":"TESTKUDOS:7","summary":"with_subscription","fulfillment_message":"Payed successfully","choices":[{"inputs":[{"kind":"token","count":1,"token_family_slug":"test-sub","valid_after":{"t_s":'$NOW'}}],"outputs":[{"kind":"token","count":1,"token_family_slug":"test-sub","valid_after":{"t_s":'$NOW'}}]}]}}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") + +if [ "$STATUS" != "200" ] +then + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected 200, order created. got: $STATUS" +fi + +ORDER_ID=$(jq -r .order_id < "$LAST_RESPONSE") +TOKEN=$(jq -r .token < "$LAST_RESPONSE") + +STATUS=$(curl http://localhost:9966/orders/"$ORDER_ID"/claim \ + -d '{"nonce":"","token":"'"$TOKEN"'"}' \ + -w "%{http_code}" -s -o "$LAST_RESPONSE") + +if [ "$STATUS" != "200" ] +then + cat "$LAST_RESPONSE" >&2 + exit_fail "Expected 200, order claimed. got: $STATUS" +fi + # # CREATE ORDER WITH NON-INVENTORY AND CHECK # -- cgit v1.2.3