mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-01-23 05:38:24 +00:00
testsuite for send_message, fix 3 found problems
This commit is contained in:
parent
81b540a4d5
commit
d26a992ecb
@ -12,7 +12,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev3-12-ga288a8d
|
||||
#### $$VERSION$$ v0.70-dev3-13-g81b540a
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -420,8 +420,8 @@ send_location() {
|
||||
send_venue() {
|
||||
local add=""
|
||||
[ "$5" = "" ] && return
|
||||
[ "$6" != "" ] add=', "foursquare_id": '"$6"''
|
||||
sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "title": "'"${4}"'"'"${add}" "$VENUE_URL"
|
||||
[ "$6" != "" ] && add=', "foursquare_id": '"$6"''
|
||||
sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "address": "'"${5}"'", "title": "'"${4}"'"'"${add}" "$VENUE_URL"
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.70-dev2-27-g2da31c1
|
||||
#### $$VERSION$$ v0.70-dev3-13-g81b540a
|
||||
|
||||
# source from commands.sh if you want ro use interactive or background jobs
|
||||
|
||||
@ -16,7 +16,7 @@ export res
|
||||
# I placed send_message here because main use case is interactive chats and background jobs
|
||||
send_message() {
|
||||
local text arg keyboard file lat long title address sent
|
||||
[ "$2" = "" ] && return 1
|
||||
[ "$2" = "" ] && return
|
||||
local mychat="$1"
|
||||
text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||
arg="$3"
|
||||
@ -32,9 +32,9 @@ send_message() {
|
||||
|
||||
long="$(echo "$2" | sed '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||
|
||||
title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||
title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||
|
||||
address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||
address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')"
|
||||
|
||||
}
|
||||
if [ "$no_keyboard" != "" ]; then
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev2-27-g2da31c1
|
||||
#### $$VERSION$$ v0.70-dev3-13-g81b540a
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
38
test/d-send_message-test.sh
Executable file
38
test/d-send_message-test.sh
Executable file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.70-dev3-13-g81b540a
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
source "./ALL-tests.inc.sh"
|
||||
|
||||
set -e
|
||||
|
||||
cd "${TESTDIR}" || exit 1
|
||||
|
||||
# source bashbot.sh function, uncomment if you want to test functions
|
||||
# shellcheck source=./bashbot.sh
|
||||
source "${TESTDIR}/bashbot.sh" source
|
||||
source "${TESTDIR}/modules/background.sh"
|
||||
|
||||
# start writing your tests here ...
|
||||
|
||||
# over write sendJson to output parameter only
|
||||
sendJson() {
|
||||
printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "${1}" "${2}" "${3}"
|
||||
}
|
||||
|
||||
# send text input to send_message
|
||||
|
||||
#set -x
|
||||
echo -n " Send line ..."
|
||||
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||||
echo -n "."
|
||||
send_message "123456" "$line" >>"${OUTPUTFILE}"
|
||||
done < "${INPUTFILE}" 2>>"${LOGFILE}"
|
||||
echo " done."
|
||||
|
||||
diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1
|
||||
echo " ... all \"send_message\" functions seems to work as expected."
|
||||
echo "${SUCCESS}"
|
||||
|
||||
|
17
test/d-send_message-test/d-send_message-test.input
Normal file
17
test/d-send_message-test/d-send_message-test.input
Normal file
@ -0,0 +1,17 @@
|
||||
# test for text only output
|
||||
This is a normal text
|
||||
This is a normal text mynewlinestartshere with a line break
|
||||
html_parse_mode This is a <b>HTML</b> text
|
||||
html_parse_mode This is a <b>HTML</b> text mynewlinestartshere with a line break
|
||||
markdown_parse_mode This is a *MARKDOWN* text
|
||||
markdown_parse_mode This is a *MARKDOWN* text mynewlinestartshere with a line break
|
||||
|
||||
# test for keyboard, file, venue output
|
||||
Text plus keyboard will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly unlikely" ]
|
||||
Text plus file will appear in chat myfilelocationstartshere /home/user/doge.jpg
|
||||
Text plus location will appear in chat mylatstartshere la10 mylongstartshere lo20
|
||||
Text plus vuene will appear in chat mylatstartshere la10 mylongstartshere lo20 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37
|
||||
All in one will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly unlikely" ] myfilelocationstartshere /home/user/doge.jpg mylatstartshere la10 mylongstartshere lo20
|
||||
|
||||
# test for new inline button
|
||||
Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..."
|
54
test/d-send_message-test/d-send_message-test.result
Normal file
54
test/d-send_message-test/d-send_message-test.result
Normal file
@ -0,0 +1,54 @@
|
||||
chat:123456 JSON:"text":"# test for text only output"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"This is a normal text"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"This is a normal text
|
||||
with a line break"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":" This is a <b>HTML</b> text","parse_mode":"html"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":" This is a <b>HTML</b> text
|
||||
with a line break","parse_mode":"html"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":" This is a *MARKDOWN* text","parse_mode":"markdown"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":" This is a *MARKDOWN* text
|
||||
with a line break","parse_mode":"markdown"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"# test for keyboard, file, venue output"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true}
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"action": "upload_photo"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendChatAction
|
||||
|
||||
chat:123456 JSON:"latitude": la10, "longitude": lo20
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendLocation
|
||||
|
||||
chat:123456 JSON:"latitude": la10, "longitude": lo20, "address": "Diagon Alley N. 37", "title": "my home"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendVenue
|
||||
|
||||
chat:123456 JSON:"text":"All in one will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true}
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"action": "upload_photo"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendChatAction
|
||||
|
||||
chat:123456 JSON:"latitude": la10, "longitude": lo20
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendLocation
|
||||
|
||||
chat:123456 JSON:"text":"# test for new inline button"
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
||||
chat:123456 JSON:"text":"Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www...""
|
||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
||||
|
Loading…
x
Reference in New Issue
Block a user