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