-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
(ns tools.ifs.parts.layouts.partials) | ||
(ns tools.ifs.parts.layouts.partials | ||
(:require | ||
[ring.middleware.anti-forgery :refer [*anti-forgery-token*]])) | ||
|
||
(defn header | ||
"Site header" | ||
|
@@ -13,7 +15,7 @@ | |
[:footer | ||
[:div.copyright | ||
[:p | ||
"© 2024 " | ||
"© 2024 " | ||
[:a {:href "https://a.possible.space"} "A Possible Space Ltd"] | ||
[:br] | ||
"Company number 11617016"]] | ||
|
@@ -25,3 +27,20 @@ | |
"See the " | ||
[:a {:href "https://github.com/apossiblespace/parts"} "source code on GitHub"] | ||
"."]]]) | ||
|
||
(defn waitlist-signup-form | ||
"Form for signing up for the waiting list" | ||
[target] | ||
[:div#signup-form | ||
[:form {:hx-post "/waitlist-signup" | ||
:hx-target target | ||
:hx-swap "outerHTML"} | ||
[:input {:type "email" | ||
:id "email" | ||
:name "email" | ||
:placeholder "[email protected]"}] | ||
[:input {:type "hidden" | ||
:id "__anti-forgery-token" | ||
:name "__anti-forgery-token" | ||
:value *anti-forgery-token* }] | ||
[:input {:type "submit" :value "Sign me up!"}]]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
(ns tools.ifs.parts.waitlist-test | ||
(:require [tools.ifs.parts.waitlist :as waitlist] | ||
[tools.ifs.helpers.test-helpers :refer [with-test-db]] | ||
[clojure.test :refer [deftest is testing use-fixtures]] | ||
[tools.ifs.parts.api.middleware :as middleware] | ||
[tools.ifs.parts.db :as db])) | ||
(:require | ||
[clojure.string :as str] | ||
[clojure.test :refer [deftest is testing use-fixtures]] | ||
[tools.ifs.helpers.test-helpers :refer [with-test-db]] | ||
[tools.ifs.parts.api.middleware :as middleware] | ||
[tools.ifs.parts.db :as db] | ||
[tools.ifs.parts.waitlist :as waitlist])) | ||
|
||
(use-fixtures :once with-test-db) | ||
|
||
(deftest test-signup | ||
(testing "saves the submitted email address in the database" | ||
(let [attrs {:email "[email protected]"} | ||
mock-request {:body attrs} | ||
(let [mock-request {:form-params {"email" "[email protected]"}} | ||
wrapped-handler (middleware/wrap-html-response waitlist/signup) | ||
response (wrapped-handler mock-request) | ||
record (db/query-one (db/sql-format {:select [:*] | ||
:from [:waitlist_signups] | ||
:where [:= :email (:email attrs)]}))] | ||
:where [:= :email "[email protected]"]}))] | ||
(is (= 201 (:status response))) | ||
(is (= "[email protected]" (:email record))) | ||
(is (= "<div id=\"thankyou\"><p>Thank you for your interest!</p></div>" (:body response)))))) | ||
(is (str/includes? (:body response) "Thank you for your interest!")))) | ||
|
||
(testing "returns a reminder to not forget the email when email is missing" | ||
(let [mock-request {:form-params {"email" ""}} | ||
wrapped-handler (middleware/wrap-html-response waitlist/signup) | ||
response (wrapped-handler mock-request)] | ||
(is (= 200 (:status response))) | ||
(is (str/includes? (:body response) "Please don't forget your email address!")))) | ||
|
||
(testing "returns a notice that the person is already on list when email is a duplicate" | ||
(let [email "[email protected]" | ||
_ (db/insert! :waitlist_signups {:email email}) | ||
mock-request {:form-params {"email" email}} | ||
wrapped-handler (middleware/wrap-html-response waitlist/signup) | ||
response (wrapped-handler mock-request)] | ||
(is (= 200 (:status response))) | ||
(is (str/includes? (:body response) "You're already on the list! We'll be in touch soon."))))) |