Stream follow updates
[akkoma] / test / pleroma / web / mastodon_api / controllers / follow_request_controller_test.exs
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
5 defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
6 use Pleroma.Web.ConnCase
7
8 alias Pleroma.User
9 alias Pleroma.Web.CommonAPI
10
11 import Pleroma.Factory
12
13 describe "locked accounts" do
14 setup do
15 user = insert(:user, is_locked: true)
16 %{conn: conn} = oauth_access(["follow"], user: user)
17 %{user: user, conn: conn}
18 end
19
20 test "/api/v1/follow_requests works", %{user: user, conn: conn} do
21 other_user = insert(:user)
22
23 {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
24 {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
25
26 assert User.following?(other_user, user) == false
27
28 conn = get(conn, "/api/v1/follow_requests")
29
30 assert [relationship] = json_response_and_validate_schema(conn, 200)
31 assert to_string(other_user.id) == relationship["id"]
32 end
33
34 test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
35 other_user = insert(:user)
36
37 {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
38 {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
39
40 user = User.get_cached_by_id(user.id)
41 other_user = User.get_cached_by_id(other_user.id)
42
43 assert User.following?(other_user, user) == false
44
45 conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/authorize")
46
47 assert relationship = json_response_and_validate_schema(conn, 200)
48 assert to_string(other_user.id) == relationship["id"]
49
50 user = User.get_cached_by_id(user.id)
51 other_user = User.get_cached_by_id(other_user.id)
52
53 assert User.following?(other_user, user) == true
54 end
55
56 test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do
57 other_user = insert(:user)
58
59 {:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
60
61 user = User.get_cached_by_id(user.id)
62
63 conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/reject")
64
65 assert relationship = json_response_and_validate_schema(conn, 200)
66 assert to_string(other_user.id) == relationship["id"]
67
68 user = User.get_cached_by_id(user.id)
69 other_user = User.get_cached_by_id(other_user.id)
70
71 assert User.following?(other_user, user) == false
72 end
73 end
74 end