Fix tests
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Mon, 2 Jan 2023 02:41:56 +0000 (02:41 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Tue, 10 Jan 2023 10:29:17 +0000 (10:29 +0000)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/pleroma/web/mastodon_api/controllers/status_controller_test.exs

index 77015241be0674fcb75ddf5fdbb15839bac2646d..2ff0e8a7444b0367d4f630c69f83c9d95f820922 100644 (file)
@@ -346,11 +346,16 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   def fix_tag(object), do: object
 
   # content map usually only has one language so this will do for now.
-  def fix_content_map(%{"contentMap" => content_map} = object) do
+  def fix_content_map(%{"contentMap" => content_map} = object) when is_map(content_map) do
     content_groups = Map.to_list(content_map)
-    {_, content} = Enum.at(content_groups, 0)
 
-    Map.put(object, "content", content)
+    if Enum.empty?(content_groups) do
+      object
+    else
+      {_, content} = Enum.at(content_groups, 0)
+
+      Map.put(object, "content", content)
+    end
   end
 
   def fix_content_map(object), do: object
index d964340cb08ce322d1ea3e5c3728701bc9cf04b4..6f04975b82e9cee76ea848ab985755c96d71c42c 100644 (file)
@@ -219,6 +219,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
       assert json_response_and_validate_schema(conn, 200)
     end
 
+    test "posting a status with an invalid language", %{conn: conn} do
+      conn =
+        conn
+        |> put_req_header("content-type", "application/json")
+        |> post("/api/v1/statuses", %{
+          "status" => "cofe",
+          "language" => "invalid"
+        })
+
+      assert %{"error" => "Invalid language"} = json_response_and_validate_schema(conn, 422)
+    end
+
     test "replying to a status", %{user: user, conn: conn} do
       {:ok, replied_to} = CommonAPI.post(user, %{status: "cofe"})