Web.AdminAPI.AdminAPIController: Fixes bugs found with ExUnit

This commit is contained in:
Haelwenn (lanodan) Monnier 2018-11-17 22:10:23 +01:00
parent 76bd80d462
commit 0ca00b3a07
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE

View File

@ -10,7 +10,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
def user_delete(conn, %{"nickname" => nickname}) do def user_delete(conn, %{"nickname" => nickname}) do
user = User.get_by_nickname(nickname) user = User.get_by_nickname(nickname)
if user[:local] == true do if user.local == true do
User.delete(user) User.delete(user)
else else
User.delete(user) User.delete(user)
@ -20,21 +20,21 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|> json(nickname) |> json(nickname)
end end
def user_create(conn, %{ def user_create(
user: %{"nickname" => nickname, "email" => email, "password" => password} = user conn,
}) do %{"nickname" => nickname, "email" => email, "password" => password}
new_user = %User{ ) do
new_user = %{
nickname: nickname, nickname: nickname,
name: user.name || nickname, name: nickname,
email: email, email: email,
password: password, password: password,
password_confirmation: password, password_confirmation: password,
bio: user.bio || "." bio: "."
} }
User.register_changeset(%User{}, new_user) User.register_changeset(%User{}, new_user)
|> Repo.insert!()
Repo.insert!(new_user)
conn conn
|> json(new_user.nickname) |> json(new_user.nickname)