Salon Appointment Scheduler - Working functionally the same as the exmples but not passing the examples tests

Hello, My code functions like the examples, and passes the variables test corrrectly, but doesn’t pass any of the functional tests… ive tried using exit to ensure the script stops running. Please, someone, what am I missing?

#!/bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"

echo -e "\n~~~ Salon Appointments Assistant ~~~\n"
echo -e "\nWhich of our lovely services would you like?\n"

#service selector
SELECT_SERVICE() {
  if [[ $1 ]]
  then
    echo -e "\n$1"
  fi

  SERVICES_DISPLAY;
  APPOINTMENT_CREATOR;
  EXIT;
}

SERVICES_DISPLAY() {
  ALL_SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")
  #display numbered list of services
  echo "$ALL_SERVICES" | while read SERVICE_ID _ NAME _
  do
    echo -e "$SERVICE_ID) $NAME"
  done
}

APPOINTMENT_CREATOR() {
  
  read SERVICE_ID_SELECTED

  if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]
  then
    SELECT_SERVICE "That's not a service we offer. Please try again.\n"
  else
    IS_ON_SERVICES_MENU=$($PSQL "SELECT service_id FROM services WHERE service_id=$SERVICE_ID_SELECTED")
        
    if [[ -z $IS_ON_SERVICES_MENU ]]
    then
      SELECT_SERVICE "That's not a service we offer. Please try again.\n"
    else
      echo -e "\nWhat is your phone number?"
      read CUSTOMER_PHONE

      if [[ ! $CUSTOMER_PHONE =~ ^[0-9-]+$ ]]
      then
        SELECT_SERVICE "Please enter an appropriate phone number."
      else
      
        IS_CUSTOMER=$($PSQL "SELECT * FROM customers WHERE phone='$CUSTOMER_PHONE'")
        
        if [[ -z $IS_CUSTOMER ]]
        then
          echo -e "\nWhat is your name?"
          read CUSTOMER_NAME
        
          if [[ -z $CUSTOMER_NAME ]]
          then
            SELECT_SERVICE "Please enter something as you name."
          else 
            INSERT_NEW_CLIENT=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
          fi
        fi

        GET_SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id=$SERVICE_ID_SELECTED") 
        SERVICE_NAME_FORMATTED=$(echo $GET_SERVICE_NAME | sed -E 's/^ *| *$//g')
        GET_CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone='$CUSTOMER_PHONE'")
        CUSTOMER_NAME_FORMATTED=$(echo $GET_CUSTOMER_NAME | sed -E 's/^ *| *$//g')

        echo -e "\nWhat time would you like to come in for your $SERVICE_NAME_FORMATTED, $CUSTOMER_NAME_FORMATTED?"
        read SERVICE_TIME

        if [[ ! $SERVICE_TIME =~ ^[0-9:]+( )?(am|pm|AM|PM)?$ ]]
        then
          SELECT_SERVICE "Please input an appropriate time."
        else
          GET_CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
          
          INSERT_APPOINTMENT_TIME=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($GET_CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')")

          echo -e "\nI have put you down for a $SERVICE_NAME_FORMATTED at $SERVICE_TIME, $CUSTOMER_NAME_FORMATTED."
        
        fi
      fi
    fi
  fi
}

EXIT() {
  echo -e "\nThank you for stopping by! Please come back soon!"
  exit
}


SELECT_SERVICE

Do you have you time field set to a varchar of 10? (If it is less, try 10 and see if that helps)

Hey, I have it set to 20, thanks for looking out! the tests I cant pass are to show a list of services and so on, but yet, they work fine in the terminal.

Maybe try posting your schema and show us the list of failed exercises so people can offer more help

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Also pls post a link to the project as well in your original topic post.

Next time I certainly will. For now, here is the link GitHub - adamdebrouwere/salon-appointment-project.

The tests I am not passing are:

  1. show a numberd list of services using the service_id and name
  2. if an invalid service number is entered, show the list again
  3. if a phone number does not exist, you should as for the customers name and then add them into the customers table.

However, as far as I can tell, they work when you execute the program, but for whatever reason, are not passing the tests.

Also, everything shows up in my DB when I query SELECT * FROM customers || appointments

can you run the code and capture the output to a file? Try to run the code as per the example.txt so it can be compared against the expected output shown below:

// Here are two examples of the output of a passing script:

~~~~~ MY SALON ~~~~~

Welcome to My Salon, how can I help you?

1) cut
2) color
3) perm
4) style
5) trim
10

I could not find that service. What would you like today?
1) cut
2) color
3) perm
4) style
5) trim
1

What's your phone number?
555-555-5555

I don't have a record for that phone number, what's your name?
Fabio

What time would you like your cut, Fabio?
10:30

I have put you down for a cut at 10:30, Fabio.


// Next example:

~~~~~ MY SALON ~~~~~

Welcome to My Salon, how can I help you?

1) cut
2) color
3) perm
4) style
5) trim
2

What's your phone number?
555-555-5555

What time would you like your color, Fabio?
11am

I have put you down for a color at 11am, Fabio.

Yup. Here are some screen shots of the output.


And all the DB tests are passing, but the funcitonal tests aren’t except it recognizes my variables being set correctly.

you should try and capture the output in a file so you can run a diff command against it and the example.txt file.

Edit: i would try to match the example test wording just in case the test is being picky.

A post was split to a new topic: Salon scheduled help needed

Solved! The issue was the test does not want any error handling other than that which it asks for.

1 Like