1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
6 use Pleroma.Web.ConnCase
9 alias Pleroma.Web.CommonAPI
11 import Pleroma.Factory
13 describe "locked accounts" do
15 user = insert(:user, is_locked: true)
16 %{conn: conn} = oauth_access(["follow"], user: user)
17 %{user: user, conn: conn}
20 test "/api/v1/follow_requests works", %{user: user, conn: conn} do
21 other_user = insert(:user)
23 {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
24 {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
26 assert User.following?(other_user, user) == false
28 conn = get(conn, "/api/v1/follow_requests")
30 assert [relationship] = json_response_and_validate_schema(conn, 200)
31 assert to_string(other_user.id) == relationship["id"]
34 test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
35 other_user = insert(:user)
37 {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
38 {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
40 user = User.get_cached_by_id(user.id)
41 other_user = User.get_cached_by_id(other_user.id)
43 assert User.following?(other_user, user) == false
45 conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/authorize")
47 assert relationship = json_response_and_validate_schema(conn, 200)
48 assert to_string(other_user.id) == relationship["id"]
50 user = User.get_cached_by_id(user.id)
51 other_user = User.get_cached_by_id(other_user.id)
53 assert User.following?(other_user, user) == true
56 test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do
57 other_user = insert(:user)
59 {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
61 user = User.get_cached_by_id(user.id)
63 conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/reject")
65 assert relationship = json_response_and_validate_schema(conn, 200)
66 assert to_string(other_user.id) == relationship["id"]
68 user = User.get_cached_by_id(user.id)
69 other_user = User.get_cached_by_id(other_user.id)
71 assert User.following?(other_user, user) == false