Skip to content

Commit

Permalink
account: WIP implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
goshatch committed Sep 3, 2024
1 parent 29fc7ba commit cce87a6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/apossiblespace/parts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/apossiblespace/parts/account.clj
Original file line number Diff line number Diff line change
@@ -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"})
24 changes: 24 additions & 0 deletions test/apossiblespace/account_test.clj
Original file line number Diff line number Diff line change
@@ -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"))
13 changes: 12 additions & 1 deletion test/apossiblespace/test_helpers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
[]
Expand Down Expand Up @@ -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)))))

0 comments on commit cce87a6

Please sign in to comment.