Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.User
  7. test "mascot upload" do
  8. %{conn: conn} = oauth_access(["write:accounts"])
  9. non_image_file = %Plug.Upload{
  10. content_type: "audio/mpeg",
  11. path: Path.absname("test/fixtures/sound.mp3"),
  12. filename: "sound.mp3"
  13. }
  14. ret_conn = put(conn, "/api/v1/pleroma/mascot", %{"file" => non_image_file})
  15. assert json_response(ret_conn, 415)
  16. file = %Plug.Upload{
  17. content_type: "image/jpg",
  18. path: Path.absname("test/fixtures/image.jpg"),
  19. filename: "an_image.jpg"
  20. }
  21. conn = put(conn, "/api/v1/pleroma/mascot", %{"file" => file})
  22. assert %{"id" => _, "type" => image} = json_response(conn, 200)
  23. end
  24. test "mascot retrieving" do
  25. %{user: user, conn: conn} = oauth_access(["read:accounts", "write:accounts"])
  26. # When user hasn't set a mascot, we should just get pleroma tan back
  27. ret_conn = get(conn, "/api/v1/pleroma/mascot")
  28. assert %{"url" => url} = json_response(ret_conn, 200)
  29. assert url =~ "pleroma-fox-tan-smol"
  30. # When a user sets their mascot, we should get that back
  31. file = %Plug.Upload{
  32. content_type: "image/jpg",
  33. path: Path.absname("test/fixtures/image.jpg"),
  34. filename: "an_image.jpg"
  35. }
  36. ret_conn = put(conn, "/api/v1/pleroma/mascot", %{"file" => file})
  37. assert json_response(ret_conn, 200)
  38. user = User.get_cached_by_id(user.id)
  39. conn =
  40. conn
  41. |> assign(:user, user)
  42. |> get("/api/v1/pleroma/mascot")
  43. assert %{"url" => url, "type" => "image"} = json_response(conn, 200)
  44. assert url =~ "an_image"
  45. end
  46. end