1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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
10 import Pleroma.Factory
12 test "mascot upload", %{conn: conn} do
15 non_image_file = %Plug.Upload{
16 content_type: "audio/mpeg",
17 path: Path.absname("test/fixtures/sound.mp3"),
23 |> assign(:user, user)
24 |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
26 assert json_response(conn, 415)
29 content_type: "image/jpg",
30 path: Path.absname("test/fixtures/image.jpg"),
31 filename: "an_image.jpg"
36 |> assign(:user, user)
37 |> put("/api/v1/pleroma/mascot", %{"file" => file})
39 assert %{"id" => _, "type" => image} = json_response(conn, 200)
42 test "mascot retrieving", %{conn: conn} do
44 # When user hasn't set a mascot, we should just get pleroma tan back
47 |> assign(:user, user)
48 |> get("/api/v1/pleroma/mascot")
50 assert %{"url" => url} = json_response(conn, 200)
51 assert url =~ "pleroma-fox-tan-smol"
53 # When a user sets their mascot, we should get that back
55 content_type: "image/jpg",
56 path: Path.absname("test/fixtures/image.jpg"),
57 filename: "an_image.jpg"
62 |> assign(:user, user)
63 |> put("/api/v1/pleroma/mascot", %{"file" => file})
65 assert json_response(conn, 200)
67 user = User.get_cached_by_id(user.id)
71 |> assign(:user, user)
72 |> get("/api/v1/pleroma/mascot")
74 assert %{"url" => url, "type" => "image"} = json_response(conn, 200)
75 assert url =~ "an_image"