Make tests great again !

(Also use only one field for public/private key pem)
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-06-14 17:25:55 +02:00
parent 32596c3624
commit ca36dd12e2
43 changed files with 498 additions and 656 deletions

View File

@@ -17,8 +17,8 @@ defmodule EventosWeb.ActivityPubController do
end
end
def event(conn, %{"name" => name, "slug" => slug}) do
with %Event{} = event <- Events.get_event_full_by_name_and_slug!(name, slug) do
def event(conn, %{"uuid" => uuid}) do
with %Event{} = event <- Events.get_event_full_by_uuid(uuid) do
conn
|> put_resp_header("content-type", "application/activity+json")
|> json(ObjectView.render("event.json", %{event: event}))

View File

@@ -2,7 +2,7 @@ defmodule EventosWeb.BotController do
use EventosWeb, :controller
alias Eventos.Actors
alias Eventos.Actors.Bot
alias Eventos.Actors.{Bot, Actor}
action_fallback EventosWeb.FallbackController
@@ -12,9 +12,9 @@ defmodule EventosWeb.BotController do
end
def create(conn, %{"bot" => bot_params}) do
with user <- Guardian.Plug.current_resource,
with user <- Guardian.Plug.current_resource(conn),
bot_params <- Map.put(bot_params, "user_id", user.id),
{:ok, actor} <- Actors.register_bot_account(%{name: bot_params["name"], summary: bot_params["summary"]}),
%Actor{} = actor <- Actors.register_bot_account(%{name: bot_params["name"], summary: bot_params["summary"]}),
bot_params <- Map.put(bot_params, "actor_id", actor.id),
{:ok, %Bot{} = bot} <- Actors.create_bot(bot_params) do
conn

View File

@@ -20,21 +20,21 @@ defmodule EventosWeb.CommentController do
end
end
def show(conn, %{"id" => id}) do
comment = Events.get_comment!(id)
def show(conn, %{"uuid" => uuid}) do
comment = Events.get_comment_with_uuid!(uuid)
render(conn, "show.json", comment: comment)
end
def update(conn, %{"id" => id, "comment" => comment_params}) do
comment = Events.get_comment!(id)
def update(conn, %{"uuid" => uuid, "comment" => comment_params}) do
comment = Events.get_comment_with_uuid!(uuid)
with {:ok, %Comment{} = comment} <- Events.update_comment(comment, comment_params) do
render(conn, "show.json", comment: comment)
end
end
def delete(conn, %{"id" => id}) do
comment = Events.get_comment!(id)
def delete(conn, %{"uuid" => uuid}) do
comment = Events.get_comment_with_uuid!(uuid)
with {:ok, %Comment{}} <- Events.delete_comment(comment) do
send_resp(conn, :no_content, "")
end

View File

@@ -9,6 +9,8 @@ defmodule EventosWeb.EventController do
alias Eventos.Export.ICalendar
alias Eventos.Addresses
import Logger
action_fallback EventosWeb.FallbackController
def index(conn, _params) do
@@ -32,11 +34,7 @@ defmodule EventosWeb.EventController do
end
defp process_address(address) do
import Logger
Logger.debug("process address")
Logger.debug(inspect address)
geom = EventosWeb.AddressController.process_geom(address["geom"])
Logger.debug(inspect geom)
case geom do
nil ->
address
@@ -53,8 +51,12 @@ defmodule EventosWeb.EventController do
end
def show(conn, %{"uuid" => uuid}) do
event = Events.get_event_full_by_uuid(uuid)
render(conn, "show.json", event: event)
case Events.get_event_full_by_uuid(uuid) do
nil ->
send_resp(conn, 404, "")
event ->
render(conn, "show.json", event: event)
end
end
def export_to_ics(conn, %{"uuid" => uuid}) do
@@ -71,8 +73,8 @@ defmodule EventosWeb.EventController do
end
def delete(conn, %{"uuid" => uuid}) do
event = Events.get_event_by_uuid(uuid)
with {:ok, %Event{}} <- Events.delete_event(event) do
with event <- Events.get_event_by_uuid(uuid),
{:ok, %Event{}} <- Events.delete_event(event) do
send_resp(conn, :no_content, "")
end
end

View File

@@ -28,8 +28,8 @@ defmodule EventosWeb.SessionController do
render(conn, "show.json", session: session)
end
def show_sessions_for_event(conn, %{"id" => event_id}) do
sessions = Events.list_sessions_for_event(event_id)
def show_sessions_for_event(conn, %{"uuid" => event_uuid}) do
sessions = Events.list_sessions_for_event(event_uuid)
render(conn, "index.json", sessions: sessions)
end

View File

@@ -16,16 +16,11 @@ defmodule EventosWeb.UserController do
end
def register(conn, %{"username" => username, "email" => email, "password" => password}) do
case Actors.register(%{email: email, password: password, username: username}) do
{:ok, %User{} = user} ->
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
with {:ok, %User{} = user} <- Actors.register(%{email: email, password: password, username: username}),
{:ok, token, _claims} <- EventosWeb.Guardian.encode_and_sign(user) do
conn
|> put_status(:created)
|> render("show_with_token.json", %{token: token, user: user})
{:error, error} ->
conn
|> put_resp_content_type("application/json")
|> send_resp(400, Poison.encode!(%{"msg" => handle_changeset_errors(error)}))
end
end