Salon appointment does what asked but tests wont pass

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

Challenge: Build a Salon Appointment Scheduler

Link to the challenge:

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?

Tests 15, 16, 18, 19, 20, 21 will not pass, but everything functions when tested.

Here is the database dump:

--
-- PostgreSQL database dump
--

-- Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

DROP DATABASE salon;
--
-- Name: salon; Type: DATABASE; Schema: -; Owner: freecodecamp
--

CREATE DATABASE salon WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';


ALTER DATABASE salon OWNER TO freecodecamp;

\connect salon

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: appointments; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.appointments (
    appointment_id integer NOT NULL,
    service_id integer,
    "time" character varying(50),
    customer_id integer
);


ALTER TABLE public.appointments OWNER TO freecodecamp;

--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.appointments_appointment_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.appointments_appointment_id_seq OWNER TO freecodecamp;

--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.appointments_appointment_id_seq OWNED BY public.appointments.appointment_id;


--
-- Name: customers; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.customers (
    customer_id integer NOT NULL,
    phone character varying(20),
    name character varying(50)
);


ALTER TABLE public.customers OWNER TO freecodecamp;

--
-- Name: customers_customer_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.customers_customer_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.customers_customer_id_seq OWNER TO freecodecamp;

--
-- Name: customers_customer_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.customers_customer_id_seq OWNED BY public.customers.customer_id;


--
-- Name: services; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.services (
    service_id integer NOT NULL,
    name character varying(50)
);


ALTER TABLE public.services OWNER TO freecodecamp;

--
-- Name: services_service_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.services_service_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.services_service_id_seq OWNER TO freecodecamp;

--
-- Name: services_service_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.services_service_id_seq OWNED BY public.services.service_id;


--
-- Name: appointments appointment_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments ALTER COLUMN appointment_id SET DEFAULT nextval('public.appointments_appointment_id_seq'::regclass);


--
-- Name: customers customer_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.customers ALTER COLUMN customer_id SET DEFAULT nextval('public.customers_customer_id_seq'::regclass);


--
-- Name: services service_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.services ALTER COLUMN service_id SET DEFAULT nextval('public.services_service_id_seq'::regclass);


--
-- Data for Name: appointments; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--

INSERT INTO public.appointments VALUES (143, 1, '10:30', 163);
INSERT INTO public.appointments VALUES (144, 2, '11am', 163);


--
-- Data for Name: customers; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--

INSERT INTO public.customers VALUES (163, '555-555-5555', 'Fabio');


--
-- Data for Name: services; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--

INSERT INTO public.services VALUES (1, 'Haircut');
INSERT INTO public.services VALUES (2, 'Highlights');
INSERT INTO public.services VALUES (3, 'Dye');
INSERT INTO public.services VALUES (4, 'Blow-dry');


--
-- Name: appointments_appointment_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.appointments_appointment_id_seq', 156, true);


--
-- Name: customers_customer_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.customers_customer_id_seq', 173, true);


--
-- Name: services_service_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.services_service_id_seq', 4, true);


--
-- Name: appointments appointments_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_pkey PRIMARY KEY (appointment_id);


--
-- Name: customers customers_phone_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.customers
    ADD CONSTRAINT customers_phone_key UNIQUE (phone);


--
-- Name: customers customers_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.customers
    ADD CONSTRAINT customers_pkey PRIMARY KEY (customer_id);


--
-- Name: services services_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.services
    ADD CONSTRAINT services_pkey PRIMARY KEY (service_id);


--
-- Name: appointments appointments_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(customer_id);


--
-- Name: appointments appointments_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.appointments
    ADD CONSTRAINT appointments_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(service_id);


--
-- PostgreSQL database dump complete
--


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.

Thanks so much for the quick reply, I was able to figure it out! Finished the assignment.

1 Like