2019-09-27 09:25:17 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 06:08:45 +01:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-09-27 09:25:17 +02: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 15:23:27 +01:00
|
|
|
setup do
|
2019-10-16 20:59:21 +02:00
|
|
|
user = insert(:user, locked: true)
|
2019-12-19 15:23:27 +01: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 09:25:17 +02:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
2019-10-10 21:35:32 +02:00
|
|
|
{:ok, other_user} = User.follow(other_user, user, "pending")
|
2019-09-27 09:25:17 +02:00
|
|
|
|
|
|
|
assert User.following?(other_user, user) == false
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
conn = get(conn, "/api/v1/follow_requests")
|
2019-09-27 09:25:17 +02:00
|
|
|
|
|
|
|
assert [relationship] = json_response(conn, 200)
|
|
|
|
assert to_string(other_user.id) == relationship["id"]
|
|
|
|
end
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
|
2019-09-27 09:25:17 +02:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
2019-10-10 21:35:32 +02:00
|
|
|
{:ok, other_user} = User.follow(other_user, user, "pending")
|
2019-09-27 09:25:17 +02: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 15:23:27 +01:00
|
|
|
conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/authorize")
|
2019-09-27 09:25:17 +02: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 15:23:27 +01:00
|
|
|
test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do
|
2019-09-27 09:25:17 +02:00
|
|
|
other_user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
|
|
|
|
|
|
|
user = User.get_cached_by_id(user.id)
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
conn = post(conn, "/api/v1/follow_requests/#{other_user.id}/reject")
|
2019-09-27 09:25:17 +02: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
|