EmojiReactionController: Return more appropriate error.
authorlain <lain@soykaf.club>
Fri, 22 May 2020 12:38:28 +0000 (14:38 +0200)
committerlain <lain@soykaf.club>
Fri, 22 May 2020 12:38:28 +0000 (14:38 +0200)
lib/pleroma/web/api_spec/operations/emoji_reaction_operation.ex
lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex
test/web/pleroma_api/controllers/emoji_reaction_controller_test.exs

index 7c08fbaa70cf1ee101e52177da42c29cd9952793..1a49fece007f9eaa8a4a068a04111160dbecb103 100644 (file)
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do
   alias OpenApiSpex.Operation
   alias OpenApiSpex.Schema
   alias Pleroma.Web.ApiSpec.Schemas.Account
+  alias Pleroma.Web.ApiSpec.Schemas.ApiError
   alias Pleroma.Web.ApiSpec.Schemas.FlakeID
   alias Pleroma.Web.ApiSpec.Schemas.Status
 
@@ -46,7 +47,8 @@ defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do
       security: [%{"oAuth" => ["write:statuses"]}],
       operationId: "EmojiReactionController.create",
       responses: %{
-        200 => Operation.response("Status", "application/json", Status)
+        200 => Operation.response("Status", "application/json", Status),
+        400 => Operation.response("Bad Request", "application/json", ApiError)
       }
     }
   end
index a002912f33be2d7da1831bd510cb427c2273cab7..19dcffdf344f72210c5424468304f4bd09de1585 100644 (file)
@@ -22,6 +22,8 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController do
 
   defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.EmojiReactionOperation
 
+  action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
+
   def index(%{assigns: %{user: user}} = conn, %{id: activity_id} = params) do
     with %Activity{} = activity <- Activity.get_by_id_with_object(activity_id),
          %Object{data: %{"reactions" => reactions}} when is_list(reactions) <-
index ee66ebf87f555defd30c2625293eb1d3135f2fef..e1bb5ebfe39c3e49791ab617df03d63c2db4d8f9 100644 (file)
@@ -33,6 +33,13 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
     assert result["pleroma"]["emoji_reactions"] == [
              %{"name" => "☕", "count" => 1, "me" => true}
            ]
+
+    # Reacting with a non-emoji
+    assert conn
+           |> assign(:user, other_user)
+           |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"]))
+           |> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/x")
+           |> json_response_and_validate_schema(400)
   end
 
   test "DELETE /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do