1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
6 use Pleroma.Web.ConnCase
10 alias Pleroma.Web.ActivityPub.ActivityPub
12 setup do: oauth_access(["write:media"])
14 describe "media upload" do
17 content_type: "image/jpg",
18 path: Path.absname("test/fixtures/image.jpg"),
19 filename: "an_image.jpg"
25 setup do: clear_config([:media_proxy])
26 setup do: clear_config([Pleroma.Upload])
28 test "returns uploaded image", %{conn: conn, image: image} do
29 desc = "Description of the image"
33 |> post("/api/v1/media", %{"file" => image, "description" => desc})
36 assert media["type"] == "image"
37 assert media["description"] == desc
40 object = Object.get_by_id(media["id"])
41 assert object.data["actor"] == User.ap_id(conn.assigns[:user])
45 describe "PUT /api/v1/media/:id" do
46 setup %{user: actor} do
48 content_type: "image/jpg",
49 path: Path.absname("test/fixtures/image.jpg"),
50 filename: "an_image.jpg"
53 {:ok, %Object{} = object} =
56 actor: User.ap_id(actor),
63 test "updates name of media", %{conn: conn, object: object} do
66 |> put("/api/v1/media/#{object.id}", %{"description" => "test-media"})
69 assert media["description"] == "test-media"
70 assert refresh_record(object).data["name"] == "test-media"
73 test "returns error when request is bad", %{conn: conn, object: object} do
76 |> put("/api/v1/media/#{object.id}", %{})
79 assert media == %{"error" => "bad_request"}