Merge branch 'pleroma-fe-2020-05-13-with-relationships-support' into 'develop'
[akkoma] / test / web / mastodon_api / controllers / media_controller_test.exs
index d872ff484554df842933be08441b74f6f2827a06..7ba1727f2caf5d58b811a2e4f10d25890cc7ac36 100644 (file)
@@ -30,8 +30,9 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
 
       media =
         conn
+        |> put_req_header("content-type", "multipart/form-data")
         |> post("/api/v1/media", %{"file" => image, "description" => desc})
-        |> json_response(:ok)
+        |> json_response_and_validate_schema(:ok)
 
       assert media["type"] == "image"
       assert media["description"] == desc
@@ -46,15 +47,16 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
 
       response =
         conn
+        |> put_req_header("content-type", "multipart/form-data")
         |> post("/api/v2/media", %{"file" => image, "description" => desc})
-        |> json_response(202)
+        |> json_response_and_validate_schema(202)
 
       assert media_id = response["id"]
 
       media =
         conn
         |> get("/api/v1/media/#{media_id}")
-        |> json_response(200)
+        |> json_response_and_validate_schema(200)
 
       assert media["type"] == "image"
       assert media["description"] == desc
@@ -85,21 +87,13 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
     test "/api/v1/media/:id good request", %{conn: conn, object: object} do
       media =
         conn
+        |> put_req_header("content-type", "multipart/form-data")
         |> put("/api/v1/media/#{object.id}", %{"description" => "test-media"})
-        |> json_response(:ok)
+        |> json_response_and_validate_schema(:ok)
 
       assert media["description"] == "test-media"
       assert refresh_record(object).data["name"] == "test-media"
     end
-
-    test "/api/v1/media/:id bad request", %{conn: conn, object: object} do
-      media =
-        conn
-        |> put("/api/v1/media/#{object.id}", %{})
-        |> json_response(400)
-
-      assert media == %{"error" => "bad_request"}
-    end
   end
 
   describe "Get media by id" do
@@ -124,7 +118,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
       media =
         conn
         |> get("/api/v1/media/#{object.id}")
-        |> json_response(:ok)
+        |> json_response_and_validate_schema(:ok)
 
       assert media["description"] == "test-media"
       assert media["type"] == "image"