diff --git a/shell-command.sh b/shell-command.sh index ae1b489..103d112 100755 --- a/shell-command.sh +++ b/shell-command.sh @@ -13,12 +13,12 @@ set -euo pipefail [ "${SCRIPT_DEBUG-}" = "1" ] && set -x +# URL endpoint to fetch the data from. +URL_ENDPOINT="${JOKE_URL_ENDPOINT:-https://official-joke-api.appspot.com/jokes/__TOPIC__/random}" + # Topic. topic="${1-}" -# URL endpoint to fetch the data from. -URL_ENDPOINT="${JOKE_URL_ENDPOINT:-https://official-joke-api.appspot.com/jokes/<>/random}" - # Flag to bypass the prompt to proceed. SHOULD_PROCEED="${SHOULD_PROCEED-}" @@ -74,7 +74,14 @@ main() { echo "Fetching joke for topic: ${topic}..." echo - response="$(curl -sL "${URL_ENDPOINT//<>/${topic}}")" + local url + url="${URL_ENDPOINT//__TOPIC__/${topic}}" + + echo + echo "URL: ${url}" + echo + + response="$(curl -sL "${url}")" # Extract 'setup' setup=$(echo "${response}" | sed -E 's/.*"setup":"([^"]+)".*/\1/') # Extract 'punchline' diff --git a/tests/bats/shell-command.bats b/tests/bats/shell-command.bats index b6ad8eb..bf9d7e2 100644 --- a/tests/bats/shell-command.bats +++ b/tests/bats/shell-command.bats @@ -18,6 +18,7 @@ export SCRIPT_FILE="shell-command.sh" @test "Data can be fetched from the API with user input" { tui_run general y assert_success + assert_output_contains "https://official-joke-api.appspot.com/jokes/general/random" } @test "Data can be fetched from the API with CLI arguments" { @@ -25,6 +26,7 @@ export SCRIPT_FILE="shell-command.sh" tui_run programming assert_success + assert_output_contains "https://official-joke-api.appspot.com/jokes/programming/random" } @test "Data can be fetched from the API with CLI arguments, aborting" {