My salon appointment scheduler does what asked, as asked, but tests will not pass.
Occasionally the box will tick green, but then untick when running the test again. Not sure what to do when everything is working as intended.
My code so far:
#!/bin/bash
# salon appointment scheduler
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
echo -e "\n<---{ Salon Services }--->\n"
SERVICES()
{
if [[ $1 ]]
then echo -e "\n$1"
fi
SERVICES=$($PSQL "SELECT service_id, name FROM services")
echo "$SERVICES" | while read SERVICE_ID BAR NAME
do
echo "$SERVICE_ID) $NAME"
done
echo "5) Exit"
read SERVICE_ID_SELECTED
case $SERVICE_ID_SELECTED in
1) SET_APPOINTMENT ;;
2) SET_APPOINTMENT ;;
3) SET_APPOINTMENT ;;
4) SET_APPOINTMENT ;;
5) EXIT ;;
*) SERVICES "You must select 1-4, or 5.\n" ;;
esac
}
SET_APPOINTMENT()
{
# get phone
echo -e "\nPlease enter your phone number."
read CUSTOMER_PHONE
CUSTOMER_NAME=$($PSQL "Select name FROM customers WHERE phone = '$CUSTOMER_PHONE'")
# if new customer get name
if [[ -z $CUSTOMER_NAME ]]
then echo -e "\nPlease enter your name."
read CUSTOMER_NAME
# insert new customer
INSERT_NEW_CUSTOMER=$($PSQL "INSERT INTO customers(phone, name) VALUES ('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
fi
# get service time
echo -e "\nWhat time would you like? Please use HH:mm format."
read SERVICE_TIME
# insert appointment
CUSTOMER_ID_FETCH=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
INSERT_APPOINTMENT=$($PSQL "INSERT INTO appointments(service_id, time, customer_id) VALUES ($SERVICE_ID_SELECTED, '$SERVICE_TIME', $CUSTOMER_ID_FETCH)")
# appointment added "I have put you down for a [service] at [time], [name]." and send to menu
SERVICES_CONFIRMATION_INFO=$($PSQL "SELECT services.name, time FROM services INNER JOIN appointments USING(service_id) INNER JOIN customers USING(customer_id) WHERE customer_id = $CUSTOMER_ID_FETCH AND time = '$SERVICE_TIME'")
SERVICES_INFO_FORMATTED=$(echo $SERVICES_CONFIRMATION_INFO | sed 's/ | / at /g')
SERVICES "I have put you down for a $SERVICES_INFO_FORMATTED, $(echo $CUSTOMER_NAME | sed -r 's/^ *| *$//g')."
}
EXIT()
{
echo -e "\nGoodbye."
}
SERVICES
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Can you share a dump of your database @dkenny17? Use the command in the instructions and then I will take a look. Also - which test(s) aren’t passing that you expect to?
The problem is that the script needs to finish so the tests can see the output. If the script doesn’t finish, the tests will timeout - which is what yours is doing. You couldn’t have known this was the issue. If I create an appointment, I get shown the list of services again at the end - the script needs to just finish. I passed all the tests by changing one word to make that happen.
I could mention that I made a few changes to the tests recently to try and make them more forgiving - I passed just now with the updated tests. If you first started your project before those changes, you are likely still using the old tests - I don’t think that will matter here. If your 10th test says You should have at least three rows in your services table for the different services you offer, one with a service_id of 1, you have the new tests. Let me know if you are still struggling and I can help some more.
I will make an issue to clarify the tests so you (and others) would have known that the script needs to finish.