Merge remote-tracking branch 'upstream/develop' into refactor/following-relationships
[akkoma] / test / web / mastodon_api / controllers / follow_request_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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.ActivityPub.ActivityPub
10
11 import Pleroma.Factory
12
13 describe "locked accounts" do
14 test "/api/v1/follow_requests works" do
15 user = insert(:user, locked: true)
16 other_user = insert(:user)
17
18 {:ok, _activity} = ActivityPub.follow(other_user, user)
19 {:ok, other_user} = User.follow(other_user, user, "pending")
20
21 assert User.following?(other_user, user) == false
22
23 conn =
24 build_conn()
25 |> assign(:user, user)
26 |> get("/api/v1/follow_requests")
27
28 assert [relationship] = json_response(conn, 200)
29 assert to_string(other_user.id) == relationship["id"]
30 end
31
32 test "/api/v1/follow_requests/:id/authorize works" do
33 user = insert(:user, locked: true)
34 other_user = insert(:user)
35
36 {:ok, _activity} = ActivityPub.follow(other_user, user)
37 {:ok, other_user} = User.follow(other_user, user, "pending")
38
39 user = User.get_cached_by_id(user.id)
40 other_user = User.get_cached_by_id(other_user.id)
41
42 assert User.following?(other_user, user) == false
43
44 conn =
45 build_conn()
46 |> assign(:user, user)
47 |> post("/api/v1/follow_requests/#{other_user.id}/authorize")
48
49 assert relationship = json_response(conn, 200)
50 assert to_string(other_user.id) == relationship["id"]
51
52 user = User.get_cached_by_id(user.id)
53 other_user = User.get_cached_by_id(other_user.id)
54
55 assert User.following?(other_user, user) == true
56 end
57
58 test "/api/v1/follow_requests/:id/reject works" do
59 user = insert(:user, locked: true)
60 other_user = insert(:user)
61
62 {:ok, _activity} = ActivityPub.follow(other_user, user)
63
64 user = User.get_cached_by_id(user.id)
65
66 conn =
67 build_conn()
68 |> assign(:user, user)
69 |> post("/api/v1/follow_requests/#{other_user.id}/reject")
70
71 assert relationship = json_response(conn, 200)
72 assert to_string(other_user.id) == relationship["id"]
73
74 user = User.get_cached_by_id(user.id)
75 other_user = User.get_cached_by_id(other_user.id)
76
77 assert User.following?(other_user, user) == false
78 end
79 end
80 end