mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
ask test script update to post
This commit is contained in:
parent
64f41d6748
commit
0463ab3cd2
2 changed files with 99 additions and 28 deletions
56
devel/tests/testScripts/ask.get.sh
Executable file
56
devel/tests/testScripts/ask.get.sh
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/bin/bash
|
||||
url=$(head -n 1 ../serverAddress)
|
||||
# url='https://api.frylabs.net'
|
||||
echo "Server url: $url"
|
||||
|
||||
simpleType='\{"type":"simple"\}'
|
||||
q=$1
|
||||
data=$2
|
||||
subj=$3
|
||||
if [ "$#" -lt 2 ]; then
|
||||
echo "min 2 params required"
|
||||
echo "Params can be:"
|
||||
echo "question data subj"
|
||||
echo "question subj"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$#" -eq 2 ]; then
|
||||
data="$simpleType"
|
||||
subj=$2
|
||||
elif [ "$#" -eq 2 ]; then
|
||||
data=$2
|
||||
subj=$3
|
||||
fi
|
||||
|
||||
../bin/hr.sh
|
||||
|
||||
data=$(node -e "console.log(encodeURIComponent('$data'));")
|
||||
|
||||
echo sending
|
||||
echo "Question: $q"
|
||||
echo "Data: $data"
|
||||
echo "Subject: $subj"
|
||||
|
||||
q=$(node -e "console.log(encodeURIComponent('$q'))")
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "node error!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
subj=$(node -e "console.log(encodeURIComponent('$subj'))")
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "node error!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Result:"
|
||||
../bin/hr.sh
|
||||
res=$(curl --cookie "sessionID=e0ac328d-86cc-4dbf-a00b-213bec6011e7" -H "Content-Type: application/json" -L -s -X GET "${url}/ask?q=${q}&data=${data}&subj=${subj}")
|
||||
echo "$res" | jq
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "jq error"
|
||||
echo "$res"
|
||||
fi
|
||||
|
||||
../bin/hr.sh
|
|
@ -3,54 +3,69 @@ url=$(head -n 1 ../serverAddress)
|
|||
# url='https://api.frylabs.net'
|
||||
echo "Server url: $url"
|
||||
|
||||
simpleType='\{"type":"simple"\}'
|
||||
simpleType="{\"type\":\"simple\"}"
|
||||
defaultTestUrl='https://elearning.uni-obuda.hu/'
|
||||
sessid='e0ac328d-86cc-4dbf-a00b-213bec6011e7'
|
||||
|
||||
q=$1
|
||||
data=$2
|
||||
subj=$3
|
||||
subj=$2
|
||||
testUrl=$3
|
||||
data=$4
|
||||
|
||||
if [ "$#" -lt 2 ]; then
|
||||
echo "min 2 params required"
|
||||
echo "Params can be:"
|
||||
echo "question data subj"
|
||||
echo "question subj"
|
||||
echo "question subj testUrl"
|
||||
echo "question subj testUrl data"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$#" -eq 2 ]; then
|
||||
data="$simpleType"
|
||||
subj=$2
|
||||
elif [ "$#" -eq 2 ]; then
|
||||
data=$2
|
||||
subj=$3
|
||||
testUrl="$defaultTestUrl"
|
||||
elif [ "$#" -eq 3 ]; then
|
||||
data="$simpleType"
|
||||
fi
|
||||
|
||||
../bin/hr.sh
|
||||
|
||||
data=$(node -e "console.log(encodeURIComponent('$data'));")
|
||||
|
||||
echo sending
|
||||
echo "Question: $q"
|
||||
echo "Data: $data"
|
||||
echo "Subject: $subj"
|
||||
|
||||
q=$(node -e "console.log(encodeURIComponent('$q'))")
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "node error!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
subj=$(node -e "console.log(encodeURIComponent('$subj'))")
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "node error!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Result:"
|
||||
echo "testUrl: $testUrl"
|
||||
echo "Data: $data"
|
||||
../bin/hr.sh
|
||||
res=$(curl --cookie "sessionID=e0ac328d-86cc-4dbf-a00b-213bec6011e7" -H "Content-Type: application/json" -L -s -X GET "${url}/ask?q=${q}&data=${data}&subj=${subj}")
|
||||
echo "sent data":
|
||||
sentdata="{
|
||||
\"questions\": [
|
||||
{
|
||||
\"q\": \"${q}\",
|
||||
\"subj\": \"${subj}\",
|
||||
\"data\": ${data}
|
||||
}
|
||||
],
|
||||
\"testUrl\": \"${testUrl}\"
|
||||
}"
|
||||
echo "$sentdata" | jq
|
||||
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "jq error, aborting sending"
|
||||
echo "$sentdata"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
../bin/hr.sh
|
||||
echo "Result:"
|
||||
res=$(curl --cookie "sessionID=${sessid}" \
|
||||
-H "Content-Type: application/json" -L -s -X POST \
|
||||
-d "${sentdata}" \
|
||||
"${url}/ask")
|
||||
|
||||
echo "$res" | jq
|
||||
|
||||
if [ "$?" -ne 0 ]; then
|
||||
echo "jq error"
|
||||
echo "$res"
|
||||
fi
|
||||
|
||||
echo "done"
|
||||
../bin/hr.sh
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue