Skip to content
Snippets Groups Projects
Commit ebe302ab authored by Ryan Senior's avatar Ryan Senior
Browse files

Switched user api errors to a map containing the error

parent 40ef0245
Branches
Tags
No related merge requests found
......@@ -52,8 +52,8 @@
last_name su/NonBlankString
email su/Email}
(api/check-superuser)
(api/check (not (db/exists? User :email email))
[400 "Email address already in use."])
(api/checkp (not (db/exists? User :email email))
"email" "Email address already in use.")
(user/invite-user! first_name last_name email password @api/*current-user*))
(api/defendpoint GET "/current"
......@@ -79,8 +79,8 @@
;; only allow updates if the specified account is active
(api/check-404 (db/exists? User, :id id, :is_active true))
;; can't change email if it's already taken BY ANOTHER ACCOUNT
(api/check (not (db/exists? User, :email email, :id [:not= id]))
[400 "Email address already associated to another user."])
(api/checkp (not (db/exists? User, :email email, :id [:not= id]))
"email" "Email address already associated to another user.")
(api/check-500 (db/update-non-nil-keys! User id
:email email
:first_name first_name
......@@ -97,7 +97,7 @@
(api/check-404 user)
;; Can only reactivate inactive users
(api/check (not (:is_active user))
[400 "Not able to reactivate an active user"])
[400 {:message "Not able to reactivate an active user"}])
(reactivate-user! user)))
......
......@@ -111,12 +111,12 @@
;; Attempting to reactivate an already active user should fail
(expect
"Not able to reactivate an active user"
{:message "Not able to reactivate an active user"}
((user->client :crowberto) :put 400 (format "user/%s/reactivate" (u/get-id (fetch-user :rasta)))))
;; Attempting to create a new user with the same email as an existing user should fail
(expect
"Email address already in use."
{:errors {:email "Email address already in use."}}
((user->client :crowberto) :post 400 "user" {:first_name "Something"
:last_name "Random"
:email (:email (fetch-user :rasta))}))
......@@ -201,7 +201,7 @@
;; ## PUT /api/user/:id
;; Test that updating a user's email to an existing inactive user's email fails
(expect
"Email address already associated to another user."
{:errors {:email "Email address already associated to another user."}}
(let [trashbird (fetch-user :trashbird)
rasta (fetch-user :rasta)]
((user->client :crowberto) :put 400 (str "user/" (u/get-id rasta)) (select-keys trashbird [:email]))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment