2019-09-27 07:25:17 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 05:08:45 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-09-27 07:25:17 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
describe "locked accounts" do
|
2019-12-19 14:23:27 +00:00
|
|
|
setup do
|
2019-10-16 18:59:21 +00:00
|
|
|
user = insert(:user, locked: true)
|
2019-12-19 14:23:27 +00:00
|
|
|
%{conn: conn} = oauth_access(["follow"], user: user)
|
|
|
|
%{user: user, conn: conn}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "/api/v1/follow_requests works", %{user: user, conn: conn} do
|
2019-09-27 07:25:17 +00:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
2020-03-28 15:49:03 +00:00
|
|
|
{:ok, other_user} = User.follow(other_user, user, :follow_pending)
|
2019-09-27 07:25:17 +00:00
|
|
|
|
|
|
|
assert User.following?(other_user, user) == false
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = get(conn, "/api/v1/follow_requests")
|
2019-09-27 07:25:17 +00:00
|
|
|
|
|
|
|
assert [relationship] = json_response(conn, 200)
|
|
|
|
assert to_string(other_user.id) == relationship["id"]
|
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
|
2019-09-27 07:25:17 +00:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
2020-03-28 15:49:03 +00:00
|
|
|
{:ok, other_user} = User.follow(other_user, user, :follow_pending)
|
2019-09-27 07:25:17 +00:00
|
|
|
|
|
|
|
user = User.get_cached_by_id(user.id)
|
|
|
|
other_user = User.get_cached_by_id(other_user.id)
|
|
|
|
|
|
|
|
assert User.following?(other_user, user) == false
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/authorize")
|
2019-09-27 07:25:17 +00:00
|
|
|
|
|
|
|
assert relationship = json_response(conn, 200)
|
|
|
|
assert to_string(other_user.id) == relationship["id"]
|
|
|
|
|
|
|
|
user = User.get_cached_by_id(user.id)
|
|
|
|
other_user = User.get_cached_by_id(other_user.id)
|
|
|
|
|
|
|
|
assert User.following?(other_user, user) == true
|
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do
|
2019-09-27 07:25:17 +00:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
|
|
|
|
|
|
|
user = User.get_cached_by_id(user.id)
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/reject")
|
2019-09-27 07:25:17 +00:00
|
|
|
|
|
|
|
assert relationship = json_response(conn, 200)
|
|
|
|
assert to_string(other_user.id) == relationship["id"]
|
|
|
|
|
|
|
|
user = User.get_cached_by_id(user.id)
|
|
|
|
other_user = User.get_cached_by_id(other_user.id)
|
|
|
|
|
|
|
|
assert User.following?(other_user, user) == false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|