Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed May 3, 2024
1 parent 33e3fc6 commit d5bd272
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions shell-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/<<TOKEN>>/random}"

# Flag to bypass the prompt to proceed.
SHOULD_PROCEED="${SHOULD_PROCEED-}"

Expand Down Expand Up @@ -74,7 +74,14 @@ main() {
echo "Fetching joke for topic: ${topic}..."
echo

response="$(curl -sL "${URL_ENDPOINT//<<TOKEN>>/${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'
Expand Down
2 changes: 2 additions & 0 deletions tests/bats/shell-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ 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" {
export SHOULD_PROCEED=y

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" {
Expand Down

0 comments on commit d5bd272

Please sign in to comment.