diff --git a/src/apossiblespace/parts.clj b/src/apossiblespace/parts.clj index 8e0e09c..5ca7944 100644 --- a/src/apossiblespace/parts.clj +++ b/src/apossiblespace/parts.clj @@ -15,7 +15,8 @@ [reitit.swagger-ui :as swagger-ui] [ring.middleware.json :refer [wrap-json-body wrap-json-response]] [apossiblespace.parts.db :as db] - [apossiblespace.parts.auth :as auth])) + [apossiblespace.parts.auth :as auth] + [apossiblespace.parts.account :as account])) ;; --------------------------------------------------------- ;; Application @@ -38,7 +39,12 @@ {:post {:handler auth/login}}] ["/logout" {:post {:handler auth/logout - :middleware [auth/jwt-auth]}}]]]] + :middleware [auth/jwt-auth]}}]] + ["/account" + {:get {:handler account/get-account} + :put {:handler account/update-account} + :delete {:handler account/delete-account} + :middleware [auth/jwt-auth]}]]] {:data {:middleware [[wrap-json-body {:keywords? true}] wrap-json-response]}}) (ring/routes diff --git a/src/apossiblespace/parts/account.clj b/src/apossiblespace/parts/account.clj new file mode 100644 index 0000000..955d718 --- /dev/null +++ b/src/apossiblespace/parts/account.clj @@ -0,0 +1,18 @@ +(ns apossiblespace.parts.account + (:require + [com.brunobonacci.mulog :as mulog])) + +(defn get-account + "Retrieve own account info" + [] + {:success "GET account"}) + +(defn update-account + "Update own account info" + [account-data] + {:success "PUT account"}) + +(defn delete-account + "Delete own account" + [confirm] + {:success "DELETE account"}) diff --git a/test/apossiblespace/account_test.clj b/test/apossiblespace/account_test.clj new file mode 100644 index 0000000..889d431 --- /dev/null +++ b/test/apossiblespace/account_test.clj @@ -0,0 +1,24 @@ +(ns apossiblespace.account-test + (:require [clojure.test :refer [deftest is testing use-fixtures]] + [apossiblespace.test-helpers :refer [with-test-db]] + [apossiblespace.test-factory :as factory])) + +(use-fixtures :once with-test-db) + +;; TODO: Use register-test-user from the helpers +(deftest test-get-account + (testing "disallows access without a valid token") + (testing "allows access with a valid token") + (testing "returns correct user information")) + +(deftest test-update-account + (testing "disallows access without a valid token") + (testing "allows access with a valid token") + (testing "correctly updates the user data") + (testing "returns updated user information")) + +(deftest delete-account + (testing "disallows access without a valid token") + (testing "allows access with a valid token") + (testing "does not delete account without confirmation param") + (testing "deletes account with confirmation param")) diff --git a/test/apossiblespace/test_helpers.clj b/test/apossiblespace/test_helpers.clj index 2c20f7b..f57c232 100644 --- a/test/apossiblespace/test_helpers.clj +++ b/test/apossiblespace/test_helpers.clj @@ -2,8 +2,11 @@ (:require [next.jdbc :as jdbc] [migratus.core :as migratus] [apossiblespace.parts.config :as conf] + [apossiblespace.parts.auth :as auth] + [apossiblespace.test-factory :as factory] [clojure.tools.logging :as log] - [clojure.java.io :as io])) + [clojure.java.io :as io] + [apossiblespace.parts.db :as db])) (defn setup-test-db [] @@ -36,3 +39,11 @@ (f) (finally (drop-all-tables ds))))) + +(defn register-test-user + "Create a user in the database from the factory" + ([] + (register-test-user {})) + ([attrs] + (let [user-data (factory/create-test-user attrs)] + (db/insert! :users (auth/prepare-user-record user-data)))))