forked from AkkomaGang/akkoma
Chat Controller: Add basic error handling.
This commit is contained in:
parent
dcb5cda324
commit
ec72cba43e
2 changed files with 15 additions and 2 deletions
|
@ -18,8 +18,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
import Pleroma.Web.ActivityPub.ObjectValidator, only: [stringify_keys: 1]
|
import Pleroma.Web.ActivityPub.ObjectValidator, only: [stringify_keys: 1]
|
||||||
|
|
||||||
# TODO
|
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
||||||
# - Error handling
|
|
||||||
|
|
||||||
plug(
|
plug(
|
||||||
OAuthScopesPlug,
|
OAuthScopesPlug,
|
||||||
|
@ -53,6 +52,8 @@ def delete_message(%{assigns: %{user: %{ap_id: actor} = user}} = conn, %{
|
||||||
conn
|
conn
|
||||||
|> put_view(ChatMessageView)
|
|> put_view(ChatMessageView)
|
||||||
|> render("show.json", for: user, object: message, chat: chat)
|
|> render("show.json", for: user, object: message, chat: chat)
|
||||||
|
else
|
||||||
|
_e -> {:error, :could_not_delete}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,8 @@ test "it deletes a message for the author of the message", %{conn: conn, user: u
|
||||||
{:ok, message} =
|
{:ok, message} =
|
||||||
CommonAPI.post_chat_message(user, recipient, "Hello darkness my old friend")
|
CommonAPI.post_chat_message(user, recipient, "Hello darkness my old friend")
|
||||||
|
|
||||||
|
{:ok, other_message} = CommonAPI.post_chat_message(recipient, user, "nico nico ni")
|
||||||
|
|
||||||
object = Object.normalize(message, false)
|
object = Object.normalize(message, false)
|
||||||
|
|
||||||
chat = Chat.get(user.id, recipient.ap_id)
|
chat = Chat.get(user.id, recipient.ap_id)
|
||||||
|
@ -99,6 +101,16 @@ test "it deletes a message for the author of the message", %{conn: conn, user: u
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert result["id"] == to_string(object.id)
|
assert result["id"] == to_string(object.id)
|
||||||
|
|
||||||
|
object = Object.normalize(other_message, false)
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> delete("/api/v1/pleroma/chats/#{chat.id}/messages/#{object.id}")
|
||||||
|
|> json_response(400)
|
||||||
|
|
||||||
|
assert result == %{"error" => "could_not_delete"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue