logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

mascot_controller_test.exs (2153B)


  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 =
  15. conn
  16. |> put_req_header("content-type", "multipart/form-data")
  17. |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
  18. assert json_response_and_validate_schema(ret_conn, 415)
  19. file = %Plug.Upload{
  20. content_type: "image/jpg",
  21. path: Path.absname("test/fixtures/image.jpg"),
  22. filename: "an_image.jpg"
  23. }
  24. conn =
  25. conn
  26. |> put_req_header("content-type", "multipart/form-data")
  27. |> put("/api/v1/pleroma/mascot", %{"file" => file})
  28. assert %{"id" => _, "type" => image} = json_response_and_validate_schema(conn, 200)
  29. end
  30. test "mascot retrieving" do
  31. %{user: user, conn: conn} = oauth_access(["read:accounts", "write:accounts"])
  32. # When user hasn't set a mascot, we should just get pleroma tan back
  33. ret_conn = get(conn, "/api/v1/pleroma/mascot")
  34. assert %{"url" => url} = json_response_and_validate_schema(ret_conn, 200)
  35. assert url =~ "pleroma-fox-tan-smol"
  36. # When a user sets their mascot, we should get that back
  37. file = %Plug.Upload{
  38. content_type: "image/jpg",
  39. path: Path.absname("test/fixtures/image.jpg"),
  40. filename: "an_image.jpg"
  41. }
  42. ret_conn =
  43. conn
  44. |> put_req_header("content-type", "multipart/form-data")
  45. |> put("/api/v1/pleroma/mascot", %{"file" => file})
  46. assert json_response_and_validate_schema(ret_conn, 200)
  47. user = User.get_cached_by_id(user.id)
  48. conn =
  49. conn
  50. |> assign(:user, user)
  51. |> get("/api/v1/pleroma/mascot")
  52. assert %{"url" => url, "type" => "image"} = json_response_and_validate_schema(conn, 200)
  53. assert url =~ "an_image"
  54. end
  55. end