Introduce new ingestion pipeline structure, implement internal Likes with it.
[akkoma] / test / web / pleroma_api / controllers / mascot_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
6 use Pleroma.Web.ConnCase
7
8 alias Pleroma.User
9
10 import Pleroma.Factory
11
12 test "mascot upload", %{conn: conn} do
13 user = insert(:user)
14
15 non_image_file = %Plug.Upload{
16 content_type: "audio/mpeg",
17 path: Path.absname("test/fixtures/sound.mp3"),
18 filename: "sound.mp3"
19 }
20
21 conn =
22 conn
23 |> assign(:user, user)
24 |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
25
26 assert json_response(conn, 415)
27
28 file = %Plug.Upload{
29 content_type: "image/jpg",
30 path: Path.absname("test/fixtures/image.jpg"),
31 filename: "an_image.jpg"
32 }
33
34 conn =
35 build_conn()
36 |> assign(:user, user)
37 |> put("/api/v1/pleroma/mascot", %{"file" => file})
38
39 assert %{"id" => _, "type" => image} = json_response(conn, 200)
40 end
41
42 test "mascot retrieving", %{conn: conn} do
43 user = insert(:user)
44 # When user hasn't set a mascot, we should just get pleroma tan back
45 conn =
46 conn
47 |> assign(:user, user)
48 |> get("/api/v1/pleroma/mascot")
49
50 assert %{"url" => url} = json_response(conn, 200)
51 assert url =~ "pleroma-fox-tan-smol"
52
53 # When a user sets their mascot, we should get that back
54 file = %Plug.Upload{
55 content_type: "image/jpg",
56 path: Path.absname("test/fixtures/image.jpg"),
57 filename: "an_image.jpg"
58 }
59
60 conn =
61 build_conn()
62 |> assign(:user, user)
63 |> put("/api/v1/pleroma/mascot", %{"file" => file})
64
65 assert json_response(conn, 200)
66
67 user = User.get_cached_by_id(user.id)
68
69 conn =
70 build_conn()
71 |> assign(:user, user)
72 |> get("/api/v1/pleroma/mascot")
73
74 assert %{"url" => url, "type" => "image"} = json_response(conn, 200)
75 assert url =~ "an_image"
76 end
77 end