logo

pleroma

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

instance_controller_test.exs (2713B)


  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.MastodonAPI.InstanceControllerTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.User
  7. import Pleroma.Factory
  8. test "get instance information", %{conn: conn} do
  9. conn = get(conn, "/api/v1/instance")
  10. assert result = json_response_and_validate_schema(conn, 200)
  11. email = Pleroma.Config.get([:instance, :email])
  12. # Note: not checking for "max_toot_chars" since it's optional
  13. assert %{
  14. "uri" => _,
  15. "title" => _,
  16. "description" => _,
  17. "version" => _,
  18. "email" => from_config_email,
  19. "urls" => %{
  20. "streaming_api" => _
  21. },
  22. "stats" => _,
  23. "thumbnail" => _,
  24. "languages" => _,
  25. "registrations" => _,
  26. "approval_required" => _,
  27. "poll_limits" => _,
  28. "upload_limit" => _,
  29. "avatar_upload_limit" => _,
  30. "background_upload_limit" => _,
  31. "banner_upload_limit" => _,
  32. "background_image" => _,
  33. "chat_limit" => _,
  34. "description_limit" => _
  35. } = result
  36. assert result["pleroma"]["metadata"]["account_activation_required"] != nil
  37. assert result["pleroma"]["metadata"]["features"]
  38. assert result["pleroma"]["metadata"]["federation"]
  39. assert result["pleroma"]["metadata"]["fields_limits"]
  40. assert result["pleroma"]["vapid_public_key"]
  41. assert email == from_config_email
  42. end
  43. test "get instance stats", %{conn: conn} do
  44. user = insert(:user, %{local: true})
  45. user2 = insert(:user, %{local: true})
  46. {:ok, _user2} = User.deactivate(user2, !user2.deactivated)
  47. insert(:user, %{local: false, nickname: "u@peer1.com"})
  48. insert(:user, %{local: false, nickname: "u@peer2.com"})
  49. {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
  50. Pleroma.Stats.force_update()
  51. conn = get(conn, "/api/v1/instance")
  52. assert result = json_response_and_validate_schema(conn, 200)
  53. stats = result["stats"]
  54. assert stats
  55. assert stats["user_count"] == 1
  56. assert stats["status_count"] == 1
  57. assert stats["domain_count"] == 2
  58. end
  59. test "get peers", %{conn: conn} do
  60. insert(:user, %{local: false, nickname: "u@peer1.com"})
  61. insert(:user, %{local: false, nickname: "u@peer2.com"})
  62. Pleroma.Stats.force_update()
  63. conn = get(conn, "/api/v1/instance/peers")
  64. assert result = json_response_and_validate_schema(conn, 200)
  65. assert ["peer1.com", "peer2.com"] == Enum.sort(result)
  66. end
  67. end