Add and fix tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-03-05 10:13:19 +01:00
parent 6de839dec2
commit 9a60704ed9
8 changed files with 55 additions and 17 deletions

View File

@@ -1028,9 +1028,9 @@ defmodule Mobilizon.Events do
end
end
def get_cached_comment_full_by_uuid("comment_" <> uuid) do
def get_cached_comment_full_by_uuid(uuid) do
Cachex.fetch(:activity_pub, "comment_" <> uuid, fn "comment_" <> uuid ->
with %Comment{} = comment <- Events.get_comment_full_from_uuid(uuid) do
with %Comment{} = comment <- get_comment_full_from_uuid(uuid) do
{:commit, comment}
else
_ -> {:ignore, nil}

View File

@@ -37,7 +37,7 @@ defmodule MobilizonWeb.ActivityPubController do
"""
@spec event(Plug.Conn.t(), map()) :: Plug.Conn.t()
def event(conn, %{"uuid" => uuid}) do
with {status, %Event{}} = event when status in [:ok, :commit] <-
with {status, %Event{} = event} when status in [:ok, :commit] <-
Events.get_cached_event_full_by_uuid(uuid),
true <- event.visibility in [:public, :unlisted] do
conn

View File

@@ -24,6 +24,6 @@ defmodule MobilizonWeb.FallbackController do
conn
|> put_status(:not_found)
|> put_view(MobilizonWeb.ErrorView)
|> render(:"404")
|> render("404.html")
end
end

View File

@@ -10,6 +10,7 @@ defmodule MobilizonWeb.PageController do
alias Mobilizon.Events.{Event, Comment}
plug(:put_layout, false)
action_fallback(MobilizonWeb.FallbackController)
def index(conn, _params) do
conn
@@ -23,9 +24,12 @@ defmodule MobilizonWeb.PageController do
with {status, %Actor{} = actor} when status in [:ok, :commit] <-
Actors.get_cached_local_actor_by_name(name) do
render_with_meta(conn, actor)
else
_ -> {:error, :not_found}
end
"activity+json" ->
# "activity-json" matches "application/activity+json" inside our config
"activity-json" ->
MobilizonWeb.ActivityPubController.call(conn, :actor)
_ ->
@@ -40,9 +44,11 @@ defmodule MobilizonWeb.PageController do
Events.get_cached_event_full_by_uuid(uuid),
true <- event.visibility in [:public, :unlisted] do
render_with_meta(conn, event)
else
_ -> {:error, :not_found}
end
"activity+json" ->
"activity-json" ->
MobilizonWeb.ActivityPubController.call(conn, :event)
_ ->
@@ -59,9 +65,11 @@ defmodule MobilizonWeb.PageController do
# TODO : Make comments maybe restricted
# true <- comment.public do
render_with_meta(conn, comment)
else
_ -> {:error, :not_found}
end
"activity+json" ->
"activity-json" ->
MobilizonWeb.ActivityPubController.call(conn, :comment)
_ ->

View File

@@ -25,7 +25,10 @@ defmodule MobilizonWeb.ErrorView do
# In case no render clause matches or no
# template is found, let's render it as 500
def template_not_found(_template, assigns) do
def template_not_found(template, assigns) do
require Logger
Logger.error("Template not found")
Logger.error(inspect(template))
render("500.html", assigns)
end
end

View File

@@ -1,7 +1,7 @@
defmodule MobilizonWeb.JsonLD.ObjectView do
use MobilizonWeb, :view
alias Mobilizon.Events.{Event, Comment}
alias Mobilizon.Events.Event
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address
alias MobilizonWeb.JsonLD.ObjectView