add test and move camp-form api to a function for the test

This commit is contained in:
Chris Cochrun 2024-05-02 11:50:59 -05:00
parent f83054b752
commit 46b4c6cf6d

View file

@ -360,7 +360,7 @@ with the image attached"
(not (cl-smtp:send-email (not (cl-smtp:send-email
"mail.tfcconnection.org" "mail.tfcconnection.org"
"no-reply@mail.tfcconnection.org" "no-reply@mail.tfcconnection.org"
'("chris@tfcconnection.org" "ethan@tfcconnection.org") '("chris@tfcconnection.org" "chris@cochrun.xyz")
(format nil "~a ~a filled out a Camp Form!" first-name last-name) (format nil "~a ~a filled out a Camp Form!" first-name last-name)
(format nil "Camp Form for ~a ~a" first-name last-name) (format nil "Camp Form for ~a ~a" first-name last-name)
:display-name "TFC ADMIN" :display-name "TFC ADMIN"
@ -485,25 +485,34 @@ with the image attached"
(hunchentoot:define-easy-handler (camp-form :uri "/camp-form") () (hunchentoot:define-easy-handler (camp-form :uri "/camp-form") ()
(let* ((request-type (hunchentoot:request-method hunchentoot:*request*)) (let* ((request-type (hunchentoot:request-method hunchentoot:*request*))
(data (hunchentoot:post-parameters* hunchentoot:*request*)) (data (hunchentoot:post-parameters* hunchentoot:*request*)))
(registration (cdr (assoc "registration" data :test 'string=))) (camp-form data)))
(health (cdr (assoc "health-form" data :test 'string=))))
(log:info data) (defun camp-form (data)
;; This is extremely necessary so that cors is right "Process the camp form"
(setf (tbnl:header-out :access-control-expose-headers) "*") (log:info data)
;; This is extremely necessary so that cors is right
(let ((registration (cdr (assoc "registration" data :test 'string=)))
(health (cdr (assoc "health-form" data :test 'string=))))
(when (boundp 'hunchentoot:*reply*)
(setf (tbnl:header-out :access-control-expose-headers) "*"))
(when data (when data
(post-camp-data data) (post-camp-data data)
(mail-camp-form data nil)) (mail-camp-form data nil))
(if (string= health "later") (if (string= health "later")
(progn (uiop:println "Selected health later") (progn (uiop:println "Selected health later")
(cond ((string= registration "now") (cond ((string= registration "now")
(setf (hunchentoot:header-out :HX-Redirect) "https://secure.myvanco.com/L-Z772/campaign/C-13JPJ") (when (boundp 'tbnl:*reply*)
(log:info (tbnl:headers-out*)) (setf (hunchentoot:header-out :HX-Redirect) "https://secure.myvanco.com/L-Z772/campaign/C-13JPJ")
(log:info "Sending them to pay now")) (log:info (tbnl:headers-out*)))
(log:info "Sending them to pay now")
"Redirecting to paying now")
((string= registration "full") ((string= registration "full")
(setf (tbnl:header-out :HX-Redirect) "https://secure.myvanco.com/L-Z772/campaign/C-13JQE") (when (boundp 'tbnl:*reply*)
(log:info (tbnl:headers-out*)) (setf (tbnl:header-out :HX-Redirect) "https://secure.myvanco.com/L-Z772/campaign/C-13JQE")
(log:info "Sending them to pay full amount")) (log:info (tbnl:headers-out*)))
(log:info "Sending them to pay full amount")
"Redirecting to paying full amount")
((string= registration "later") ((string= registration "later")
(let ((first-name (cdr (assoc "first-name" data :test 'string=))) (let ((first-name (cdr (assoc "first-name" data :test 'string=)))
(last-name (cdr (assoc "last-name" data :test 'string=)))) (last-name (cdr (assoc "last-name" data :test 'string=))))
@ -519,9 +528,11 @@ with the image attached"
(:p :class "text-md" (:p :class "text-md"
"If you'd like to pay for your registration go to the donate tab in the top right when you are ready and find the camp registration option."))))))) "If you'd like to pay for your registration go to the donate tab in the top right when you are ready and find the camp registration option.")))))))
(when (string= health "now") (when (string= health "now")
(setf (tbnl:header-out :HX-Redirect) (format nil "/camp-health-form/?registration=~A" registration)) (when (boundp 'tbnl:*reply*)
(log:info (tbnl:headers-out*)) (setf (tbnl:header-out :HX-Redirect) (format nil "/camp-health-form/?registration=~A" registration))
(log:info "Sending them to the health form for camp"))))) (log:info (tbnl:headers-out*)))
(log:info "Sending them to the health form for camp")
"Redirecting to the health form"))))
(defun main () (defun main ()
(start-server 4242) (start-server 4242)
@ -541,5 +552,17 @@ with the image attached"
(uiop:quit))) (uiop:quit)))
(error (c) (format t "Woops, an unknown error occured:~&~a~&" c)))) (error (c) (format t "Woops, an unknown error occured:~&~a~&" c))))
(fiveam:test testing-things (fiveam:test test-camp-form
(fiveam:is (= 2 (+ 1 1)))) (fiveam:is (string= "Redirecting to the health form" (camp-form test-data))))
(setf test-data '(("first-name" . "Frodo") ("last-name" . "Braggins")
("parent-first-name" . "Bilbo")
("parent-last-name" . "Braggins")
("birth-date" . "1857-04-06") ("gender" . "Male")
("street" . "341 West Hobbiton") ("city" . "The Shire")
("state" . "Middle Earth") ("zip" . "88888") ("grade" . "freshman")
("parent-phone" . "9998887777")
("parent-email" . "bilbosmells@theshire.com")
("allergies" . "No") ("week" . "week1")
("shirt" . "medium") ("final-agreement" . "yes")
("health-form" . "now") ("registration" . "now")))