mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-05-31 17:30:53 +00:00
finalize process_message test
This commit is contained in:
parent
26c8523589
commit
48e6f64d58
|
@ -10,7 +10,7 @@
|
||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ 0.70-dev-21-gd4cd756
|
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
|
@ -579,7 +579,7 @@ process_message() {
|
||||||
# Document
|
# Document
|
||||||
URLS[DOCUMENT]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","document","file_id"' <"$TMP")")")"
|
URLS[DOCUMENT]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","document","file_id"' <"$TMP")")")"
|
||||||
# Photo
|
# Photo
|
||||||
URLS[PHOTO]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","photo",.*,"file_id"' <"$TMP")")")"
|
URLS[PHOTO]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","photo",0,"file_id"' <"$TMP")")")"
|
||||||
# Sticker
|
# Sticker
|
||||||
URLS[STICKER]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","sticker","file_id"' <"$TMP")")")"
|
URLS[STICKER]="$(get_file "$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","sticker","file_id"' <"$TMP")")")"
|
||||||
# Video
|
# Video
|
||||||
|
@ -597,8 +597,8 @@ process_message() {
|
||||||
CAPTION="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","caption"' <"$TMP")")"
|
CAPTION="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","caption"' <"$TMP")")"
|
||||||
|
|
||||||
# Location
|
# Location
|
||||||
LOCATION[LONGITUDE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","location","longitude"' <"$TMP")")"
|
LOCATION[LONGITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","longitude"' <"$TMP")"
|
||||||
LOCATION[LATITUDE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","location","latitude"' <"$TMP")")"
|
LOCATION[LATITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","latitude"' <"$TMP")"
|
||||||
NAME="$(echo "${URLS[*]}" | sed 's/.*\///g')"
|
NAME="$(echo "${URLS[*]}" | sed 's/.*\///g')"
|
||||||
#rm "$TMP"
|
#rm "$TMP"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-21-gd4cd756
|
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
||||||
|
|
||||||
# common variables
|
# common variables
|
||||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||||
|
@ -22,6 +22,26 @@ export SUCCESS NOSUCCESS
|
||||||
SUCCESS=" OK"
|
SUCCESS=" OK"
|
||||||
NOSUCCESS=" FAILED!"
|
NOSUCCESS=" FAILED!"
|
||||||
|
|
||||||
|
# default input, reference and output files
|
||||||
|
INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input"
|
||||||
|
REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result"
|
||||||
|
OUTPUTFILE="${TESTDIR}/${REFDIR}.out"
|
||||||
|
|
||||||
|
# print arrays in reproducible order
|
||||||
|
print_array() {
|
||||||
|
local idx t
|
||||||
|
local arrays=( "${@}" )
|
||||||
|
for idx in "${arrays[@]}"; do
|
||||||
|
declare -n temp="$idx"
|
||||||
|
for t in "${!temp[@]}"; do
|
||||||
|
printf "%s:\t%s\t%s\n" "$idx" "$t" "${temp[$t]}"
|
||||||
|
done | sort
|
||||||
|
done | grep -v '^USER: 0'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
######
|
||||||
|
# lets go ...
|
||||||
echo "Running ${TESTNAME#? } ..."
|
echo "Running ${TESTNAME#? } ..."
|
||||||
echo "............................"
|
echo "............................"
|
||||||
[ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1
|
[ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# this has to run once atfer git clone
|
# this has to run once atfer git clone
|
||||||
# and every time we create new hooks
|
# and every time we create new hooks
|
||||||
#### $$VERSION$$ 0.70-dev-21-gd4cd756
|
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-21-gd4cd756
|
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
||||||
|
|
||||||
../dev/hooks/pre-commit.sh
|
../dev/hooks/pre-commit.sh
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-21-gd4cd756
|
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
||||||
|
|
||||||
../dev/hooks/pre-push.sh
|
../dev/hooks/pre-push.sh
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-21-gd4cd756
|
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ 0.70-dev-21-gd4cd756
|
#### $$VERSION$$ 0.70-dev-22-g26c8523
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
|
@ -12,32 +12,22 @@ cd "${TESTDIR}" || exit 1
|
||||||
# shellcheck source=./bashbot.sh
|
# shellcheck source=./bashbot.sh
|
||||||
source "${TESTDIR}/bashbot.sh" source
|
source "${TESTDIR}/bashbot.sh" source
|
||||||
|
|
||||||
export UPDATE
|
|
||||||
UPDATE="$(cat ${DIRME}/${REFDIR}/${REFDIR}.input)"
|
|
||||||
|
|
||||||
# overwrite get_file for test
|
# overwrite get_file for test
|
||||||
get_file() {
|
get_file() {
|
||||||
echo "$1"
|
echo "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# get telegram input from file
|
||||||
|
export UPDATE
|
||||||
|
UPDATE="$(cat "${INPUTFILE}")"
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
process_message "0" >>${LOGFILE} 2>&1
|
process_message "0" >>"${LOGFILE}" 2>&1; set +x
|
||||||
set +x
|
|
||||||
cd "${DIRME}" || exit 1
|
cd "${DIRME}" || exit 1
|
||||||
|
|
||||||
# output processed input
|
# output processed input
|
||||||
|
echo "Diff process_message input and output ..."
|
||||||
print_array() {
|
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE" >"${OUTPUTFILE}"
|
||||||
local idx t
|
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
|
||||||
local arrays=( "${@}" )
|
|
||||||
for idx in "${arrays[@]}"; do
|
|
||||||
declare -n temp="$idx"
|
|
||||||
for t in "${!temp[@]}"; do
|
|
||||||
printf "%s:\t%s\t%s\n" "$idx" "$t" "${temp[$t]}"
|
|
||||||
done | sort
|
|
||||||
done | grep -v '^USER: 0'
|
|
||||||
}
|
|
||||||
|
|
||||||
print_array "USER" "CHAT" "REPLYTO" "FORWARD" "URLS" "CONTACT" "CAPTION" "LOCATION" "MESSAGE"
|
|
||||||
|
|
||||||
echo "${SUCCESS}"
|
echo "${SUCCESS}"
|
||||||
|
|
|
@ -29,9 +29,9 @@
|
||||||
["result",0,"message","reply_to_message","entities",0,"length"] 14
|
["result",0,"message","reply_to_message","entities",0,"length"] 14
|
||||||
["result",0,"message","reply_to_message","entities",0,"type"] "bold"
|
["result",0,"message","reply_to_message","entities",0,"type"] "bold"
|
||||||
["result",0,"message","reply_to_message","entities",0] {"offset":12,"length":14,"type":"bold"}
|
["result",0,"message","reply_to_message","entities",0] {"offset":12,"length":14,"type":"bold"}
|
||||||
["result",0,"message","reply_to_message","entities",0,"offset"] 61
|
["result",0,"message","reply_to_message","entities",1,"offset"] 61
|
||||||
["result",0,"message","reply_to_message","entities",0,"length"] 5
|
["result",0,"message","reply_to_message","entities",1,"length"] 5
|
||||||
["result",0,"message","reply_to_message","entities",0,"type"] "bot_command"
|
["result",0,"message","reply_to_message","entities",1,"type"] "bot_command"
|
||||||
["result",0,"message","text"] "\ud83d\ude02\ud83d\ude1d\ud83d\udc4c\u263a\u2764\ud83d\ude15\ud83d\ude08#\u20e3\ud83c\udf0f\ud83c\udf89\ud83d\ude4a\ud83d\ude49\u2615\ud83d\ude80\u2708\ud83d\ude82\ud83d\udcaf\u2714\u303d\ud83d\udd1a"
|
["result",0,"message","text"] "\ud83d\ude02\ud83d\ude1d\ud83d\udc4c\u263a\u2764\ud83d\ude15\ud83d\ude08#\u20e3\ud83c\udf0f\ud83c\udf89\ud83d\ude4a\ud83d\ude49\u2615\ud83d\ude80\u2708\ud83d\ude82\ud83d\udcaf\u2714\u303d\ud83d\udd1a"
|
||||||
["result",0,"message","forward_from","id"] 123456789
|
["result",0,"message","forward_from","id"] 123456789
|
||||||
["result",0,"message","forward_from","is_bot"] false
|
["result",0,"message","forward_from","is_bot"] false
|
||||||
|
@ -45,10 +45,10 @@
|
||||||
["result",0,"message","photo",0,"width"] 67
|
["result",0,"message","photo",0,"width"] 67
|
||||||
["result",0,"message","photo",0,"height"] 90
|
["result",0,"message","photo",0,"height"] 90
|
||||||
["result",0,"message","photo",0] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC","file_size":1468,"width":67,"height":90}
|
["result",0,"message","photo",0] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC","file_size":1468,"width":67,"height":90}
|
||||||
["result",0,"message","photo",0,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC"
|
["result",0,"message","photo",1,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC"
|
||||||
["result",0,"message","photo",0,"file_size"] 25125
|
["result",0,"message","photo",1,"file_size"] 25125
|
||||||
["result",0,"message","photo",0,"width"] 240
|
["result",0,"message","photo",1,"width"] 240
|
||||||
["result",0,"message","photo",0,"height"] 320
|
["result",0,"message","photo",1,"height"] 320
|
||||||
["result",0,"message","photo",1] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC","file_size":25125,"width":240,"height":320}
|
["result",0,"message","photo",1] {"file_id":"AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOFli9a5TF3rbPgDAAEC","file_size":25125,"width":240,"height":320}
|
||||||
["result",0,"message","photo",2,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABCVM2ZSdqfMZbfgDAAEC"
|
["result",0,"message","photo",2,"file_id"] "AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABCVM2ZSdqfMZbfgDAAEC"
|
||||||
["result",0,"message","photo",2,"file_size"] 127851
|
["result",0,"message","photo",2,"file_size"] 127851
|
||||||
|
@ -75,7 +75,8 @@
|
||||||
["result",0,"message","venue","address"] "Am Rhein 1"
|
["result",0,"message","venue","address"] "Am Rhein 1"
|
||||||
["result",0,"message","venue","foursquare_id"] "4c4321afce54e21eee980d1a"
|
["result",0,"message","venue","foursquare_id"] "4c4321afce54e21eee980d1a"
|
||||||
["result",0,"message","contact","phone_number"] "222222"
|
["result",0,"message","contact","phone_number"] "222222"
|
||||||
["result",0,"message","contact","first_name"] "ADAC Pannenhilfe"
|
["result",0,"message","contact","first_name"] "ADAC"
|
||||||
|
["result",0,"message","contact","last_name"] "Pannenhilfe"
|
||||||
["result",0,"message","contact","vcard"] "BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"
|
["result",0,"message","contact","vcard"] "BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"
|
||||||
["result",0,"message","voice","duration"] 2
|
["result",0,"message","voice","duration"] 2
|
||||||
["result",0,"message","voice","mime_type"] "audio/ogg"
|
["result",0,"message","voice","mime_type"] "audio/ogg"
|
||||||
|
|
37
test/d-process_message-test/d-process_message-test.result
Normal file
37
test/d-process_message-test/d-process_message-test.result
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
USER: FIRST_NAME Kay
|
||||||
|
USER: ID 123456789
|
||||||
|
USER: LAST_NAME M
|
||||||
|
USER: USERNAME Gnadelwartz
|
||||||
|
CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS
|
||||||
|
CHAT: FIRST_NAME Test
|
||||||
|
CHAT: ID 123456789
|
||||||
|
CHAT: LAST_NAME Bot
|
||||||
|
CHAT: TITLE
|
||||||
|
CHAT: TYPE private
|
||||||
|
CHAT: USERNAME BotTest
|
||||||
|
REPLYTO: 0 Ich bin der Deal-O-Mat Bot. Für eine Liste der Befehle sende /help
|
||||||
|
REPLYTO: FIRST_NAME dealzbot
|
||||||
|
REPLYTO: ID 6542
|
||||||
|
REPLYTO: LAST_NAME
|
||||||
|
REPLYTO: UID 987654321
|
||||||
|
REPLYTO: USERNAME Deal_O_Mat_bot
|
||||||
|
FORWARD: FIRST_NAME Kay
|
||||||
|
FORWARD: ID 6541
|
||||||
|
FORWARD: LAST_NAME M
|
||||||
|
FORWARD: UID 123456789
|
||||||
|
FORWARD: USERNAME Gnadelwartz
|
||||||
|
URLS: AUDIO
|
||||||
|
URLS: DOCUMENT
|
||||||
|
URLS: PHOTO AgADAgADL6oxG-Gw4EndCWGl2WUfUo1pXw8ABOusSilDGzAYa_gDAAEC
|
||||||
|
URLS: STICKER
|
||||||
|
URLS: VIDEO
|
||||||
|
URLS: VOICE AwADAgADOAQAAqd24Emnm_VGmmVEuAI
|
||||||
|
CONTACT: FIRST_NAME ADAC
|
||||||
|
CONTACT: LAST_NAME Pannenhilfe
|
||||||
|
CONTACT: NUMBER 222222
|
||||||
|
CONTACT: USER_ID
|
||||||
|
CAPTION: 0
|
||||||
|
LOCATION: LATITUDE 49.631824
|
||||||
|
LOCATION: LONGITUDE 8.377072
|
||||||
|
MESSAGE: 0 😂😝👌☺❤😕😈#⃣🌏🎉🙊🙉☕🚀✈🚂💯✔〽🔚
|
||||||
|
MESSAGE: ID 6541
|
Loading…
Reference in New Issue
Block a user