From 206eff3edb148e305907b9f497c1c47f527bc981 Mon Sep 17 00:00:00 2001 From: Gosha Tcherednitchenko Date: Wed, 6 Nov 2024 16:40:32 +0000 Subject: [PATCH] chore: Apply standard-clj fixes --- build.clj | 7 +- cljs/tools/ifs/parts/core.cljs | 6 +- dev/mulog_events.clj | 20 ++-- dev/portal.clj | 1 - dev/user.clj | 19 ++-- shadow-cljs.edn | 6 +- src/tools/ifs/parts.clj | 109 +++++++++---------- src/tools/ifs/parts/api/auth.clj | 4 +- src/tools/ifs/parts/api/middleware.clj | 60 +++++----- src/tools/ifs/parts/auth.clj | 26 ++--- src/tools/ifs/parts/db.clj | 22 ++-- src/tools/ifs/parts/entity/user.clj | 15 ++- src/tools/ifs/parts/layouts/main.clj | 37 ++++--- src/tools/ifs/parts/layouts/partials.clj | 2 +- src/tools/ifs/parts/pages.clj | 25 +++-- src/tools/ifs/parts/waitlist.clj | 18 +-- test/tools/ifs/helpers/test_factory.clj | 14 +-- test/tools/ifs/helpers/test_helpers.clj | 13 ++- test/tools/ifs/parts/api/account_test.clj | 13 ++- test/tools/ifs/parts/api/auth_test.clj | 20 ++-- test/tools/ifs/parts/api/middleware_test.clj | 18 +-- test/tools/ifs/parts/auth_test.clj | 16 +-- test/tools/ifs/parts/entity/user_test.clj | 27 ++--- 23 files changed, 252 insertions(+), 246 deletions(-) diff --git a/build.clj b/build.clj index 1dbfcb1..e7ae07b 100644 --- a/build.clj +++ b/build.clj @@ -21,8 +21,8 @@ (ns build (:require - [clojure.tools.build.api :as build-api] - [clojure.pprint :as pprint])) + [clojure.pprint :as pprint] + [clojure.tools.build.api :as build-api])) ;; --------------------------------------------------------- ;; Project configuration @@ -53,10 +53,9 @@ Checks that `.` and `/` directories are not deleted" [directory] (when - (not (contains? #{"." "/"} directory)) + (not (contains? #{"." "/"} directory)) (build-api/delete {:path (or (:path directory) "target")}))) - (defn uberjar "Create an archive containing Clojure and the build of the project Merge command line configuration to the default project config" diff --git a/cljs/tools/ifs/parts/core.cljs b/cljs/tools/ifs/parts/core.cljs index e6ad150..09e9acc 100644 --- a/cljs/tools/ifs/parts/core.cljs +++ b/cljs/tools/ifs/parts/core.cljs @@ -1,6 +1,8 @@ (ns tools.ifs.parts.core - (:require ["d3" :as d3] - ["htmx.org" :default htmx])) + (:require + ["d3" :as d3] + ["htmx.org"] + [htmx])) (def node-data [{:type "exile"} diff --git a/dev/mulog_events.clj b/dev/mulog_events.clj index 745d3d4..fa68482 100644 --- a/dev/mulog_events.clj +++ b/dev/mulog_events.clj @@ -8,13 +8,13 @@ (ns mulog-events (:require - [com.brunobonacci.mulog :as mulog] + [com.brunobonacci.mulog :as mulog] [com.brunobonacci.mulog.buffer :as mulog-buffer])) ;; --------------------------------------------------------- ;; Set event global context ;; - information added to every event for REPL workflow -(mulog/set-global-context! {:app-name "parts Service", +(mulog/set-global-context! {:app-name "parts Service" :version "0.1.0", :env "dev"}) ;; --------------------------------------------------------- @@ -23,13 +23,13 @@ (deftype TapPublisher [buffer transform] - com.brunobonacci.mulog.publisher.PPublisher - (agent-buffer [_] buffer) - (publish-delay [_] 200) - (publish [_ buffer] - (doseq [item (transform (map second (mulog-buffer/items buffer)))] - (tap> item)) - (mulog-buffer/clear buffer))) + com.brunobonacci.mulog.publisher.PPublisher + (agent-buffer [_] buffer) + (publish-delay [_] 200) + (publish [_ buffer] + (doseq [item (transform (map second (mulog-buffer/items buffer)))] + (tap> item)) + (mulog-buffer/clear buffer))) #_{:clj-kondo/ignore [:unused-private-var]} (defn ^:private tap-events @@ -41,7 +41,7 @@ and other tap sources `mulog-tap-publisher` to stop publisher" (mulog/start-publisher! - {:type :custom, :fqn-function "mulog-events/tap-events"})) + {:type :custom, :fqn-function "mulog-events/tap-events"})) #_{:clj-kondo/ignore [:unused-public-var]} (defn stop diff --git a/dev/portal.clj b/dev/portal.clj index 63492cb..bf371fb 100644 --- a/dev/portal.clj +++ b/dev/portal.clj @@ -3,7 +3,6 @@ ;; Data inspector [portal.api :as inspect])) - ;; --------------------------------------------------------- ;; Start Portal and capture all evaluation results diff --git a/dev/user.clj b/dev/user.clj index 1e5b01c..584d0e8 100644 --- a/dev/user.clj +++ b/dev/user.clj @@ -10,22 +10,21 @@ ;; - alias included in the Emacs `.dir-locals.el` file ;; --------------------------------------------------------- - (ns user "Tools for REPL Driven Development" (:require + [clojure.tools.namespace.repl :as namespace] + [com.brunobonacci.mulog :as mulog] ; Global context & Tap publisher ;; REPL Workflow - [mulog-events] ; Event Logging - [com.brunobonacci.mulog :as mulog] ; Global context & Tap publisher + [mulog-events] ; Event Logging [portal] - [portal.api :as inspect] ; Data inspector + [portal.api :as inspect] ; Data inspector [tools.ifs.parts :as parts] - [tools.ifs.parts.config :as config] - [tools.ifs.parts.db :as db] - [tools.ifs.parts.api.auth :as auth] [tools.ifs.parts.api.account :as account] + [tools.ifs.parts.api.auth :as auth] [tools.ifs.parts.api.middleware :as middleware] - [clojure.tools.namespace.repl :as namespace])) + [tools.ifs.parts.config :as config] + [tools.ifs.parts.db :as db])) ;; --------------------------------------------------------- ;; Help @@ -69,8 +68,8 @@ ;; Avoid reloading `dev` code ;; - code in `dev` directory should be evaluated if changed to reload into repl (println - "Set REPL refresh directories to " - (namespace/set-refresh-dirs "src" "resources")) + "Set REPL refresh directories to " + (namespace/set-refresh-dirs "src" "resources")) ;; --------------------------------------------------------- ;; --------------------------------------------------------- diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 502ab4c..537ef60 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -1,5 +1,4 @@ -{ - :source-paths +{:source-paths ["cljs"] :dependencies @@ -18,5 +17,4 @@ :asset-path "/js" :modules {:main {:init-fn tools.ifs.parts.core/init}} :devtools {:http-root "resources/public" - :http-port 8020}}} - } + :http-port 8020}}}} diff --git a/src/tools/ifs/parts.clj b/src/tools/ifs/parts.clj index e406cf0..cda6285 100644 --- a/src/tools/ifs/parts.clj +++ b/src/tools/ifs/parts.clj @@ -9,38 +9,38 @@ ;; --------------------------------------------------------- (ns tools.ifs.parts - (:gen-class) (:require [com.brunobonacci.mulog :as mulog] [org.httpkit.server :as server] - [reitit.ring :as ring] [reitit.coercion.spec] + [reitit.ring :as ring] [reitit.swagger :as swagger] [reitit.swagger-ui :as swagger-ui] [ring.middleware.json :refer [wrap-json-body wrap-json-response]] [ring.middleware.params :refer [wrap-params]] + [tools.ifs.parts.api.account :as account] + [tools.ifs.parts.api.auth :as auth] [tools.ifs.parts.api.middleware :as middleware] [tools.ifs.parts.db :as db] [tools.ifs.parts.pages :as pages] - [tools.ifs.parts.api.auth :as auth] - [tools.ifs.parts.api.account :as account] - [tools.ifs.parts.waitlist :as waitlist])) + [tools.ifs.parts.waitlist :as waitlist]) + (:gen-class)) ;; --------------------------------------------------------- ;; Application (def prelaunch-app (middleware/wrap-default-middlewares - (ring/ring-handler - (ring/router - [["/" {:get {:handler #(pages/home-page %)}}] - ["/up" - {:get {:handler (fn [_] {:status 200 :body "OK"})}}] - ["/waitlist-signup" {:post {:handler #(waitlist/signup %)}}]] - {:data {:middleware [wrap-params - middleware/exception - middleware/logging - middleware/wrap-html-response]}})))) + (ring/ring-handler + (ring/router + [["/" {:get {:handler #(pages/home-page %)}}] + ["/up" + {:get {:handler (fn [_] {:status 200 :body "OK"})}}] + ["/waitlist-signup" {:post {:handler #(waitlist/signup %)}}]] + {:data {:middleware [wrap-params + middleware/exception + middleware/logging + middleware/wrap-html-response]}})))) ;; TODO: We need to later figure out a way to combine HTML routes and API ;; routes. @@ -55,44 +55,44 @@ ;; routes will remain. (def app (middleware/wrap-default-middlewares - (ring/ring-handler - (ring/router - [["/swagger.json" - {:get {:no-doc true - :swagger {:info {:title "Parts API" - :description "API for Parts"}} - :handler (swagger/create-swagger-handler)}}] - ["/api" - ["/ping" - {:get {:swagger {:tags ["Utility"]} - :handler (fn [_] {:status 200 :body {:message "Pong!"}})}}] - ["/auth" {:swagger {:tags ["Authentication"]}} - ["/login" - {:post {:handler auth/login}}] - ["/logout" - {:post {:handler auth/logout - :middleware [middleware/jwt-auth]}}]] - ["/account" {:swagger {:tags ["Account"]}} - ["" - {:get {:handler account/get-account} - :patch {:handler account/update-account} - :delete {:handler account/delete-account} - :middleware [middleware/jwt-auth]}] - ["/register" - {:post {:handler account/register-account}}]]] - ["/" {:get {:handler #(pages/home-page %)}}]] - {:data {:middleware [wrap-params - middleware/exception - middleware/logging - [wrap-json-body {:keywords? true}] - wrap-json-response - middleware/wrap-jwt-authentication]}}) - (ring/routes - (swagger-ui/create-swagger-ui-handler - {:path "/swagger-ui" - :config {:validatorUrl nil - :operationsSorter "alpha"}}) - (ring/create-default-handler))))) + (ring/ring-handler + (ring/router + [["/swagger.json" + {:get {:no-doc true + :swagger {:info {:title "Parts API" + :description "API for Parts"}} + :handler (swagger/create-swagger-handler)}}] + ["/api" + ["/ping" + {:get {:swagger {:tags ["Utility"]} + :handler (fn [_] {:status 200 :body {:message "Pong!"}})}}] + ["/auth" {:swagger {:tags ["Authentication"]}} + ["/login" + {:post {:handler auth/login}}] + ["/logout" + {:post {:handler auth/logout + :middleware [middleware/jwt-auth]}}]] + ["/account" {:swagger {:tags ["Account"]}} + ["" + {:get {:handler account/get-account} + :patch {:handler account/update-account} + :delete {:handler account/delete-account} + :middleware [middleware/jwt-auth]}] + ["/register" + {:post {:handler account/register-account}}]]] + ["/" {:get {:handler #(pages/home-page %)}}]] + {:data {:middleware [wrap-params + middleware/exception + middleware/logging + [wrap-json-body {:keywords? true}] + wrap-json-response + middleware/wrap-jwt-authentication]}}) + (ring/routes + (swagger-ui/create-swagger-ui-handler + {:path "/swagger-ui" + :config {:validatorUrl nil + :operationsSorter "alpha"}}) + (ring/create-default-handler))))) (defn start-server "Starts the web server" @@ -105,7 +105,7 @@ [& args] (let [port (or (some-> (first args) Integer/parseInt) 3000)] (mulog/set-global-context! - {:app-name "Parts" :version "0.1.0-SNAPSHOT"}) + {:app-name "Parts" :version "0.1.0-SNAPSHOT"}) (mulog/log ::application-startup :arguments args :port port) (db/init-db) (let [stop-fn (start-server port)] @@ -116,7 +116,6 @@ ;; --------------------------------------------------------- - ;; --------------------------------------------------------- ;; Rick Comment #_{:clj-kondo/ignore [:redefined-var]} diff --git a/src/tools/ifs/parts/api/auth.clj b/src/tools/ifs/parts/api/auth.clj index 6256f1e..30a2e48 100644 --- a/src/tools/ifs/parts/api/auth.clj +++ b/src/tools/ifs/parts/api/auth.clj @@ -1,8 +1,8 @@ (ns tools.ifs.parts.api.auth (:require - [tools.ifs.parts.auth :as auth] + [com.brunobonacci.mulog :as mulog] [ring.util.response :as response] - [com.brunobonacci.mulog :as mulog])) + [tools.ifs.parts.auth :as auth])) (defn login [request] diff --git a/src/tools/ifs/parts/api/middleware.clj b/src/tools/ifs/parts/api/middleware.clj index 3d302d0..3b12740 100644 --- a/src/tools/ifs/parts/api/middleware.clj +++ b/src/tools/ifs/parts/api/middleware.clj @@ -1,17 +1,19 @@ (ns tools.ifs.parts.api.middleware - (:require [reitit.ring.middleware.exception :as exception] - [com.brunobonacci.mulog :as mulog] - [buddy.auth.middleware :refer [wrap-authentication wrap-authorization]] - [buddy.auth :refer [authenticated?]] - [ring.util.response :as response] - [clojure.string :as str] - [tools.ifs.parts.auth :as auth] - [ring.middleware.defaults :refer [wrap-defaults site-defaults]] - [ring.middleware.resource :refer [wrap-resource]] - [ring.middleware.content-type :refer [wrap-content-type]] - [ring.middleware.session :refer [wrap-session]] - [ring.middleware.session.cookie :refer [cookie-store]]) - (:import (org.sqlite SQLiteException))) + (:require + [buddy.auth :refer [authenticated?]] + [buddy.auth.middleware :refer [wrap-authentication wrap-authorization]] + [clojure.string :as str] + [com.brunobonacci.mulog :as mulog] + [reitit.ring.middleware.exception :as exception] + [ring.middleware.content-type :refer [wrap-content-type]] + [ring.middleware.defaults :refer [site-defaults wrap-defaults]] + [ring.middleware.resource :refer [wrap-resource]] + [ring.middleware.session :refer [wrap-session]] + [ring.middleware.session.cookie :refer [cookie-store]] + [ring.util.response :as response] + [tools.ifs.parts.auth :as auth]) + (:import + (org.sqlite SQLiteException))) (defn exception-handler "Generic exceptions handler" @@ -34,30 +36,29 @@ (mulog/log ::sqlite-exception :error error-message) {:status 409 :body {:error (or (some - (fn [[k, v]] (when (str/includes? error-message k) v)) - sqlite-errors) + (fn [[k, v]] (when (str/includes? error-message k) v)) + sqlite-errors) "A database constraint was violated")}})) (def exception "Middleware handling exceptions" (exception/create-exception-middleware - (merge - exception/default-handlers - {;; ex-info with :type :validation - :validation (exception-handler "Invalid data" 400) + (merge + exception/default-handlers + {;; ex-info with :type :validation + :validation (exception-handler "Invalid data" 400) - :not-found (exception-handler "Resource not found" 404) + :not-found (exception-handler "Resource not found" 404) - ;; SQLite exceptions - SQLiteException sqlite-constraint-violation-handler + ;; SQLite exceptions + SQLiteException sqlite-constraint-violation-handler - ;; Default - ::exception/default - (fn [^Exception e _request] - (mulog/log ::unhandled-exception :error (.getMessage e)) - {:status 500 - :body {:error "Internal server error"}}) - }))) + ;; Default + ::exception/default + (fn [^Exception e _request] + (mulog/log ::unhandled-exception :error (.getMessage e)) + {:status 500 + :body {:error "Internal server error"}})}))) (defn logging "Middleware logging each incoming request" @@ -84,7 +85,6 @@ (-> (response/response {:error "Unauthorized"}) (response/status 401))))) - (defn wrap-default-middlewares "Wrap in the middlewares defined by ring-defaults" [handler] diff --git a/src/tools/ifs/parts/auth.clj b/src/tools/ifs/parts/auth.clj index 15b334f..0f9a9f4 100644 --- a/src/tools/ifs/parts/auth.clj +++ b/src/tools/ifs/parts/auth.clj @@ -1,28 +1,28 @@ (ns tools.ifs.parts.auth (:require - [buddy.sign.jwt :as jwt] [buddy.auth.backends :as backends] [buddy.hashers :as hashers] - [tools.ifs.parts.db :as db] + [buddy.sign.jwt :as jwt] + [com.brunobonacci.mulog :as mulog] [tools.ifs.parts.config :as conf] - [com.brunobonacci.mulog :as mulog]) + [tools.ifs.parts.db :as db]) (:import - [java.time Instant])) + (java.time Instant))) (def secret (conf/jwt-secret (conf/config))) (def backend (backends/jws - {:secret secret - :options {:alg :hs256} - :on-error (fn [_request ex] - (mulog/log ::auth-backend :error (.getMessage ex)) - nil) - :token-name "Bearer" - :auth-fn (fn [claims] - (mulog/log ::auth-backend-auth-fn :claims claims) - claims)})) + {:secret secret + :options {:alg :hs256} + :on-error (fn [_request ex] + (mulog/log ::auth-backend :error (.getMessage ex)) + nil) + :token-name "Bearer" + :auth-fn (fn [claims] + (mulog/log ::auth-backend-auth-fn :claims claims) + claims)})) (defn create-token "Create a JWT token that will expire in 1 hour" diff --git a/src/tools/ifs/parts/db.clj b/src/tools/ifs/parts/db.clj index c6913ae..39ac429 100644 --- a/src/tools/ifs/parts/db.clj +++ b/src/tools/ifs/parts/db.clj @@ -1,14 +1,14 @@ (ns tools.ifs.parts.db (:require + [clojure.string :as str] + [com.brunobonacci.mulog :as mulog] + [honey.sql :as sql] + [migratus.core :as migratus] [next.jdbc :as jdbc] [next.jdbc.result-set :as rs] - [migratus.core :as migratus] - [honey.sql :as sql] - [com.brunobonacci.mulog :as mulog] - [tools.ifs.parts.config :as conf] - [clojure.string :as str]) + [tools.ifs.parts.config :as conf]) (:import - [java.util UUID])) + (java.util UUID))) (def db-spec {:dbtype "sqlite" @@ -70,10 +70,10 @@ [table data] (let [data-with-uuid (assoc data :id (generate-uuid))] (first (jdbc/execute! write-datasource - (sql/format {:insert-into (keyword table) - :values [data-with-uuid] - :returning :*}) - {:builder-fn rs/as-unqualified-maps})))) + (sql/format {:insert-into (keyword table) + :values [data-with-uuid] + :returning :*}) + {:builder-fn rs/as-unqualified-maps})))) (defn update! [table data where-clause] @@ -81,7 +81,7 @@ (sql/format {:update (keyword table) :set data :where where-clause - :returning :* }) + :returning :*}) {:builder-fn rs/as-unqualified-maps})) (defn delete! diff --git a/src/tools/ifs/parts/entity/user.clj b/src/tools/ifs/parts/entity/user.clj index 02e7646..f16f940 100644 --- a/src/tools/ifs/parts/entity/user.clj +++ b/src/tools/ifs/parts/entity/user.clj @@ -25,8 +25,7 @@ "Ensure we are not trying to save attributes that cannot be updated" [attrs] (-> attrs - (select-keys allowed-update-fields) - ) + (select-keys allowed-update-fields)) (select-keys attrs allowed-update-fields)) (defn- set-password-hash @@ -48,10 +47,10 @@ "Retrieve a user record from the database" [id] (if-let [user (db/query-one - (db/sql-format - {:select [:id :email :username :display_name :role] - :from [:users] - :where [:= :id id]}))] + (db/sql-format + {:select [:id :email :username :display_name :role] + :from [:users] + :where [:= :id id]}))] (remove-sensitive-data user) (throw (ex-info "User not found" {:type :not-found})))) @@ -64,7 +63,7 @@ validate-attrs set-password-hash)] (remove-sensitive-data - (first (db/update! :users sanitized-attrs [:= :id id]))))) + (first (db/update! :users sanitized-attrs [:= :id id]))))) (defn create! "Create a new user record with the provided attributes" @@ -73,7 +72,7 @@ validate-attrs set-password-hash)] (remove-sensitive-data - (db/insert! :users validated-attrs)))) + (db/insert! :users validated-attrs)))) ;; TODO: Don't forget to delete other data associated with this user (defn delete! diff --git a/src/tools/ifs/parts/layouts/main.clj b/src/tools/ifs/parts/layouts/main.clj index caa747c..ec978e4 100644 --- a/src/tools/ifs/parts/layouts/main.clj +++ b/src/tools/ifs/parts/layouts/main.clj @@ -1,24 +1,25 @@ (ns tools.ifs.parts.layouts.main - (:require [hiccup2.core :refer [html]])) + (:require + [hiccup2.core :refer [html]])) (defn layout "Fundamental application layout" [title & content] (html - [:head - [:meta {:charset "utf-8"}] - [:meta {:name "viewport" :content "width=device-width, initial-scale=1"}] - [:meta {:name "description" :content "Parts is a mapping tool for IFS practitioners to keep track of, visualise, and explore the relationships between their clients’ parts."}] - [:link {:rel "icon" :sizes "192x192" :href "/images/icons/favicon.png"}] - [:link {:rel "apple-touch-icon" :href "/images/icons/favicon.png"}] - [:title (str title " — Parts")] - [:link {:rel "stylesheet" :href "/css/style.css"}] - [:link {:rel "preconnect" :href "https://fonts.googleapis.com"}] - [:link {:rel "preconnect" :href "https://fonts.gstatic.com" :crossorigin true}] - [:link {:rel "stylesheet" :href "https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&display=swap"}] - [:script {:src "/js/main.js"}] - [:script {:defer true - :data-domain "parts.ifs.tools" - :src "https://plausible.io/js/script.outbound-links.tagged-events.js"}]] - [:body - [:section.container content]])) + [:head + [:meta {:charset "utf-8"}] + [:meta {:name "viewport" :content "width=device-width, initial-scale=1"}] + [:meta {:name "description" :content "Parts is a mapping tool for IFS practitioners to keep track of, visualise, and explore the relationships between their clients’ parts."}] + [:link {:rel "icon" :sizes "192x192" :href "/images/icons/favicon.png"}] + [:link {:rel "apple-touch-icon" :href "/images/icons/favicon.png"}] + [:title (str title " — Parts")] + [:link {:rel "stylesheet" :href "/css/style.css"}] + [:link {:rel "preconnect" :href "https://fonts.googleapis.com"}] + [:link {:rel "preconnect" :href "https://fonts.gstatic.com" :crossorigin true}] + [:link {:rel "stylesheet" :href "https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&display=swap"}] + [:script {:src "/js/main.js"}] + [:script {:defer true + :data-domain "parts.ifs.tools" + :src "https://plausible.io/js/script.outbound-links.tagged-events.js"}]] + [:body + [:section.container content]])) diff --git a/src/tools/ifs/parts/layouts/partials.clj b/src/tools/ifs/parts/layouts/partials.clj index 4ce3b04..4b087e5 100644 --- a/src/tools/ifs/parts/layouts/partials.clj +++ b/src/tools/ifs/parts/layouts/partials.clj @@ -45,5 +45,5 @@ [:input {:type "hidden" :id "__anti-forgery-token" :name "__anti-forgery-token" - :value *anti-forgery-token* }] + :value *anti-forgery-token*}] [:input {:type "submit" :value "Sign me up!"}]]]) diff --git a/src/tools/ifs/parts/pages.clj b/src/tools/ifs/parts/pages.clj index eabb252..40aa9ee 100644 --- a/src/tools/ifs/parts/pages.clj +++ b/src/tools/ifs/parts/pages.clj @@ -1,26 +1,27 @@ (ns tools.ifs.parts.pages - (:require [hiccup2.core :refer [html]] - [tools.ifs.parts.layouts.main :refer [layout]] - [tools.ifs.parts.layouts.partials :refer [header footer waitlist-signup-form]] - [ring.util.response :as response])) + (:require + [hiccup2.core :refer [html]] + [ring.util.response :as response] + [tools.ifs.parts.layouts.main :refer [layout]] + [tools.ifs.parts.layouts.partials :refer [footer header waitlist-signup-form]])) (defn system-graph "Page rendering the graph of a system" [system-id] (response/response - (html - (layout "System" - (header) - [:div [:h2 "System"]] - [:div#chart] - (footer))))) + (html + (layout "System" + (header) + [:div [:h2 "System"]] + [:div#chart] + (footer))))) (defn home-page "Page rendered for GET /" [_] (-> (response/response - (html - (layout + (html + (layout "Mapping tools for IFS practitioners and their clients" (header) [:section.hero diff --git a/src/tools/ifs/parts/waitlist.clj b/src/tools/ifs/parts/waitlist.clj index a004c77..3321dab 100644 --- a/src/tools/ifs/parts/waitlist.clj +++ b/src/tools/ifs/parts/waitlist.clj @@ -1,11 +1,11 @@ (ns tools.ifs.parts.waitlist (:require - [hiccup2.core :refer [html]] + [clojure.string :as str] [com.brunobonacci.mulog :as mulog] + [hiccup2.core :refer [html]] [ring.util.response :as response] [tools.ifs.parts.db :as db] - [tools.ifs.parts.layouts.partials :as partials] - [clojure.string :as str])) + [tools.ifs.parts.layouts.partials :as partials])) (defn- valid-email? "Check if the email is valid" @@ -27,12 +27,12 @@ (cond (or (nil? email) (str/blank? email)) (-> (response/response - (form-with-message "Please don't forget your email address!")) + (form-with-message "Please don't forget your email address!")) (response/status 200)) (not (valid-email? email)) (-> (response/response - (form-with-message "Sorry, that's not a valid email address.")) + (form-with-message "Sorry, that's not a valid email address.")) (response/status 200)) :else @@ -40,11 +40,11 @@ (db/insert! :waitlist_signups {:email email}) (mulog/log ::waitlist_signup :email email) (-> (response/response - (html [:div.success - [:p "Thank you for your interest! We'll be in touch soon."]])) + (html [:div.success + [:p "Thank you for your interest! We'll be in touch soon."]])) (response/status 201)) (catch Exception _e (-> (response/response - (html [:div.success - [:p "You're already on the list! We'll be in touch soon."]])) + (html [:div.success + [:p "You're already on the list! We'll be in touch soon."]])) (response/status 200))))))) diff --git a/test/tools/ifs/helpers/test_factory.clj b/test/tools/ifs/helpers/test_factory.clj index 9036637..22e5ed6 100644 --- a/test/tools/ifs/helpers/test_factory.clj +++ b/test/tools/ifs/helpers/test_factory.clj @@ -12,13 +12,13 @@ ([attrs] (let [id (generate-unique-id)] (merge - {:email (str "test" id "@example.com") - :username (str "username" id) - :display_name (str "Test User " id) - :password (str "password" id) - :password_confirmation (str "password" id) - :role "client"} - attrs)))) + {:email (str "test" id "@example.com") + :username (str "username" id) + :display_name (str "Test User " id) + :password (str "password" id) + :password_confirmation (str "password" id) + :role "client"} + attrs)))) (defn create-test-users [n] diff --git a/test/tools/ifs/helpers/test_helpers.clj b/test/tools/ifs/helpers/test_helpers.clj index dbf3098..06ae5cc 100644 --- a/test/tools/ifs/helpers/test_helpers.clj +++ b/test/tools/ifs/helpers/test_helpers.clj @@ -1,10 +1,11 @@ (ns tools.ifs.helpers.test-helpers - (:require [next.jdbc :as jdbc] - [migratus.core :as migratus] - [tools.ifs.parts.config :as conf] - [tools.ifs.parts.entity.user :as user] - [tools.ifs.helpers.test-factory :as factory] - [clojure.tools.logging :as log])) + (:require + [clojure.tools.logging :as log] + [migratus.core :as migratus] + [next.jdbc :as jdbc] + [tools.ifs.helpers.test-factory :as factory] + [tools.ifs.parts.config :as conf] + [tools.ifs.parts.entity.user :as user])) (defn setup-test-db [] diff --git a/test/tools/ifs/parts/api/account_test.clj b/test/tools/ifs/parts/api/account_test.clj index f774c69..03f8231 100644 --- a/test/tools/ifs/parts/api/account_test.clj +++ b/test/tools/ifs/parts/api/account_test.clj @@ -1,9 +1,10 @@ (ns tools.ifs.parts.api.account-test - (:require [clojure.test :refer [deftest is testing use-fixtures]] - [tools.ifs.helpers.test-helpers :refer [with-test-db register-test-user]] - [tools.ifs.helpers.test-factory :as factory] - [tools.ifs.parts.db :as db] - [tools.ifs.parts.api.account :as account])) + (:require + [clojure.test :refer [deftest is testing use-fixtures]] + [tools.ifs.helpers.test-factory :as factory] + [tools.ifs.helpers.test-helpers :refer [register-test-user with-test-db]] + [tools.ifs.parts.api.account :as account] + [tools.ifs.parts.db :as db])) (use-fixtures :once with-test-db) @@ -32,7 +33,7 @@ (is (= {:email (str "added" (:email user)) :display_name "Updated"} updated-fields) - (is (not (contains? (:body response) :password_hash)))))) + (is (not (contains? (:body response) :password_hash)))))) (testing "does not update where no updatable data is passed" (let [user (register-test-user) diff --git a/test/tools/ifs/parts/api/auth_test.clj b/test/tools/ifs/parts/api/auth_test.clj index c9103e7..676d9ac 100644 --- a/test/tools/ifs/parts/api/auth_test.clj +++ b/test/tools/ifs/parts/api/auth_test.clj @@ -1,13 +1,15 @@ (ns tools.ifs.parts.api.auth-test - (:require [clojure.test :refer [deftest is testing use-fixtures]] - [tools.ifs.parts.auth :as auth-utils] - [tools.ifs.parts.api.auth :as auth] - [tools.ifs.parts.entity.user :as user] - [tools.ifs.parts.api.account :as account] - [buddy.sign.jwt :as jwt] - [tools.ifs.helpers.test-helpers :refer [with-test-db]] - [tools.ifs.helpers.test-factory :as factory]) - (:import [java.time Instant])) + (:require + [buddy.sign.jwt :as jwt] + [clojure.test :refer [deftest is testing use-fixtures]] + [tools.ifs.helpers.test-factory :as factory] + [tools.ifs.helpers.test-helpers :refer [with-test-db]] + [tools.ifs.parts.api.account :as account] + [tools.ifs.parts.api.auth :as auth] + [tools.ifs.parts.auth :as auth-utils] + [tools.ifs.parts.entity.user :as user]) + (:import + (java.time Instant))) (use-fixtures :once with-test-db) diff --git a/test/tools/ifs/parts/api/middleware_test.clj b/test/tools/ifs/parts/api/middleware_test.clj index 6b62114..c9a5745 100644 --- a/test/tools/ifs/parts/api/middleware_test.clj +++ b/test/tools/ifs/parts/api/middleware_test.clj @@ -1,15 +1,17 @@ (ns tools.ifs.parts.api.middleware-test - (:require [clojure.test :refer [deftest is testing]] - [tools.ifs.parts.api.middleware :as middleware] - [ring.mock.request :as mock] - [reitit.ring :as ring]) - (:import (org.sqlite SQLiteException SQLiteErrorCode))) + (:require + [clojure.test :refer [deftest is testing]] + [reitit.ring :as ring] + [ring.mock.request :as mock] + [tools.ifs.parts.api.middleware :as middleware]) + (:import + (org.sqlite SQLiteErrorCode SQLiteException))) (defn create-app [handler] (ring/ring-handler - (ring/router - [["/test" {:handler handler}]] - {:data {:middleware [middleware/exception]}}))) + (ring/router + [["/test" {:handler handler}]] + {:data {:middleware [middleware/exception]}}))) (deftest exception-middleware-test (testing "passes through successful responses" diff --git a/test/tools/ifs/parts/auth_test.clj b/test/tools/ifs/parts/auth_test.clj index 02b122c..8b21aba 100644 --- a/test/tools/ifs/parts/auth_test.clj +++ b/test/tools/ifs/parts/auth_test.clj @@ -1,11 +1,13 @@ (ns tools.ifs.parts.auth-test - (:require [clojure.test :refer [deftest is testing use-fixtures]] - [tools.ifs.parts.auth :as auth] - [tools.ifs.parts.entity.user :as user] - [buddy.sign.jwt :as jwt] - [tools.ifs.helpers.test-helpers :refer [with-test-db]] - [tools.ifs.helpers.test-factory :as factory]) - (:import [java.time Instant])) + (:require + [buddy.sign.jwt :as jwt] + [clojure.test :refer [deftest is testing use-fixtures]] + [tools.ifs.helpers.test-factory :as factory] + [tools.ifs.helpers.test-helpers :refer [with-test-db]] + [tools.ifs.parts.auth :as auth] + [tools.ifs.parts.entity.user :as user]) + (:import + (java.time Instant))) (use-fixtures :once with-test-db) diff --git a/test/tools/ifs/parts/entity/user_test.clj b/test/tools/ifs/parts/entity/user_test.clj index 0bf2a2c..db7f9ed 100644 --- a/test/tools/ifs/parts/entity/user_test.clj +++ b/test/tools/ifs/parts/entity/user_test.clj @@ -1,8 +1,9 @@ (ns tools.ifs.parts.entity.user-test - (:require [clojure.test :refer [deftest is testing use-fixtures]] - [tools.ifs.helpers.test-helpers :refer [with-test-db register-test-user]] - [tools.ifs.helpers.test-factory :as factory] - [tools.ifs.parts.entity.user :as user])) + (:require + [clojure.test :refer [deftest is testing use-fixtures]] + [tools.ifs.helpers.test-factory :as factory] + [tools.ifs.helpers.test-helpers :refer [register-test-user with-test-db]] + [tools.ifs.parts.entity.user :as user])) (use-fixtures :once with-test-db) @@ -41,16 +42,16 @@ (let [db-user (register-test-user)] (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Password and confirmation do not match" (user/update! - (:id db-user) - {:password "password12345" - :password_confirmation "wordpass54321"}))))) + (:id db-user) + {:password "password12345" + :password_confirmation "wordpass54321"}))))) (testing "throws when no ID is passed" (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Missing User ID" (user/update! - nil - {:password "password12345" - :password_confirmation "password12345"}))))) + nil + {:password "password12345" + :password_confirmation "password12345"}))))) (deftest test-create! (testing "creates the user entity in the database" @@ -76,9 +77,9 @@ (let [attrs (factory/create-test-user)] (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Password and confirmation do not match" (user/create! - (assoc attrs - :password "password12345" - :password_confirmation "wordpass54321"))))))) + (assoc attrs + :password "password12345" + :password_confirmation "wordpass54321"))))))) (deftest test-delete! (testing "deletes the user entity from the database"