logo

pleroma

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

follow_request_controller_test.exs (2421B)


  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.FollowRequestControllerTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.User
  7. alias Pleroma.Web.CommonAPI
  8. import Pleroma.Factory
  9. describe "locked accounts" do
  10. setup do
  11. user = insert(:user, locked: true)
  12. %{conn: conn} = oauth_access(["follow"], user: user)
  13. %{user: user, conn: conn}
  14. end
  15. test "/api/v1/follow_requests works", %{user: user, conn: conn} do
  16. other_user = insert(:user)
  17. {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
  18. {:ok, other_user} = User.follow(other_user, user, :follow_pending)
  19. assert User.following?(other_user, user) == false
  20. conn = get(conn, "/api/v1/follow_requests")
  21. assert [relationship] = json_response_and_validate_schema(conn, 200)
  22. assert to_string(other_user.id) == relationship["id"]
  23. end
  24. test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
  25. other_user = insert(:user)
  26. {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
  27. {:ok, other_user} = User.follow(other_user, user, :follow_pending)
  28. user = User.get_cached_by_id(user.id)
  29. other_user = User.get_cached_by_id(other_user.id)
  30. assert User.following?(other_user, user) == false
  31. conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/authorize")
  32. assert relationship = json_response_and_validate_schema(conn, 200)
  33. assert to_string(other_user.id) == relationship["id"]
  34. user = User.get_cached_by_id(user.id)
  35. other_user = User.get_cached_by_id(other_user.id)
  36. assert User.following?(other_user, user) == true
  37. end
  38. test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do
  39. other_user = insert(:user)
  40. {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
  41. user = User.get_cached_by_id(user.id)
  42. conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/reject")
  43. assert relationship = json_response_and_validate_schema(conn, 200)
  44. assert to_string(other_user.id) == relationship["id"]
  45. user = User.get_cached_by_id(user.id)
  46. other_user = User.get_cached_by_id(other_user.id)
  47. assert User.following?(other_user, user) == false
  48. end
  49. end
  50. end