logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

mascot_controller_test.exs (2355B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 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, async: true
  6. alias Pleroma.UnstubbedConfigMock, as: ConfigMock
  7. alias Pleroma.User
  8. import Mox
  9. test "mascot upload" do
  10. %{conn: conn} = oauth_access(["write:accounts"])
  11. non_image_file = %Plug.Upload{
  12. content_type: "audio/mpeg",
  13. path: Path.absname("test/fixtures/sound.mp3"),
  14. filename: "sound.mp3"
  15. }
  16. ret_conn =
  17. conn
  18. |> put_req_header("content-type", "multipart/form-data")
  19. |> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
  20. assert json_response_and_validate_schema(ret_conn, 415)
  21. file = %Plug.Upload{
  22. content_type: "image/jpeg",
  23. path: Path.absname("test/fixtures/image.jpg"),
  24. filename: "an_image.jpg"
  25. }
  26. ConfigMock
  27. |> stub_with(Pleroma.Test.StaticConfig)
  28. conn =
  29. conn
  30. |> put_req_header("content-type", "multipart/form-data")
  31. |> put("/api/v1/pleroma/mascot", %{"file" => file})
  32. assert %{"id" => _, "type" => _image} = json_response_and_validate_schema(conn, 200)
  33. end
  34. test "mascot retrieving" do
  35. %{user: user, conn: conn} = oauth_access(["read:accounts", "write:accounts"])
  36. # When user hasn't set a mascot, we should just get pleroma tan back
  37. ret_conn = get(conn, "/api/v1/pleroma/mascot")
  38. assert %{"url" => url} = json_response_and_validate_schema(ret_conn, 200)
  39. assert url =~ "pleroma-fox-tan-smol"
  40. # When a user sets their mascot, we should get that back
  41. file = %Plug.Upload{
  42. content_type: "image/jpeg",
  43. path: Path.absname("test/fixtures/image.jpg"),
  44. filename: "an_image.jpg"
  45. }
  46. ConfigMock
  47. |> stub_with(Pleroma.Test.StaticConfig)
  48. ret_conn =
  49. conn
  50. |> put_req_header("content-type", "multipart/form-data")
  51. |> put("/api/v1/pleroma/mascot", %{"file" => file})
  52. assert json_response_and_validate_schema(ret_conn, 200)
  53. user = User.get_cached_by_id(user.id)
  54. conn =
  55. conn
  56. |> assign(:user, user)
  57. |> get("/api/v1/pleroma/mascot")
  58. assert %{"url" => url, "type" => "image"} = json_response_and_validate_schema(conn, 200)
  59. assert url =~ "an_image"
  60. end
  61. end