1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
6 use Pleroma.Web.ConnCase, async: true
10 test "mascot upload" do
11 %{conn: conn} = oauth_access(["write:accounts"])
13 non_image_file = %Plug.Upload{
14 content_type: "audio/mpeg",
15 path: Path.absname("test/fixtures/sound.mp3"),
21 |> put_req_header("content-type", "multipart/form-data")
22 |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
24 assert json_response_and_validate_schema(ret_conn, 415)
27 content_type: "image/jpeg",
28 path: Path.absname("test/fixtures/image.jpg"),
29 filename: "an_image.jpg"
34 |> put_req_header("content-type", "multipart/form-data")
35 |> put("/api/v1/pleroma/mascot", %{"file" => file})
37 assert %{"id" => _, "type" => _image} = json_response_and_validate_schema(conn, 200)
40 test "mascot retrieving" do
41 %{user: user, conn: conn} = oauth_access(["read:accounts", "write:accounts"])
43 # When user hasn't set a mascot, we should just get pleroma tan back
44 ret_conn = get(conn, "/api/v1/pleroma/mascot")
46 assert %{"url" => url} = json_response_and_validate_schema(ret_conn, 200)
47 assert url =~ "pleroma-fox-tan-smol"
49 # When a user sets their mascot, we should get that back
51 content_type: "image/jpeg",
52 path: Path.absname("test/fixtures/image.jpg"),
53 filename: "an_image.jpg"
58 |> put_req_header("content-type", "multipart/form-data")
59 |> put("/api/v1/pleroma/mascot", %{"file" => file})
61 assert json_response_and_validate_schema(ret_conn, 200)
63 user = User.get_cached_by_id(user.id)
67 |> assign(:user, user)
68 |> get("/api/v1/pleroma/mascot")
70 assert %{"url" => url, "type" => "image"} = json_response_and_validate_schema(conn, 200)
71 assert url =~ "an_image"