2019-08-13 21:12:37 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-08-13 21:12:37 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
2023-08-01 10:43:50 +00:00
|
|
|
use Pleroma.Web.ConnCase, async: false
|
2019-08-13 21:12:37 +00:00
|
|
|
|
|
|
|
alias Pleroma.Notification
|
|
|
|
alias Pleroma.ScheduledActivity
|
|
|
|
alias Pleroma.User
|
2019-08-31 07:20:34 +00:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-08-13 21:12:37 +00:00
|
|
|
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
describe "follow/3" do
|
2019-10-16 18:59:21 +00:00
|
|
|
test "returns error when followed user is deactivated" do
|
2019-08-13 21:12:37 +00:00
|
|
|
follower = insert(:user)
|
2020-10-12 22:42:27 +00:00
|
|
|
user = insert(:user, local: true, is_active: false)
|
2020-08-04 13:08:51 +00:00
|
|
|
assert {:error, _error} = MastodonAPI.follow(follower, user)
|
2019-08-13 21:12:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "following for user" do
|
|
|
|
follower = insert(:user)
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, follower} = MastodonAPI.follow(follower, user)
|
|
|
|
assert User.following?(follower, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns ok if user already followed" do
|
|
|
|
follower = insert(:user)
|
|
|
|
user = insert(:user)
|
2020-12-01 20:17:52 +00:00
|
|
|
{:ok, follower, user} = User.follow(follower, user)
|
2019-08-13 21:12:37 +00:00
|
|
|
{:ok, follower} = MastodonAPI.follow(follower, refresh_record(user))
|
|
|
|
assert User.following?(follower, user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "get_followers/2" do
|
|
|
|
test "returns user followers" do
|
|
|
|
follower1_user = insert(:user)
|
|
|
|
follower2_user = insert(:user)
|
|
|
|
user = insert(:user)
|
2020-12-01 20:17:52 +00:00
|
|
|
{:ok, _follower1_user, _user} = User.follow(follower1_user, user)
|
|
|
|
{:ok, follower2_user, _user} = User.follow(follower2_user, user)
|
2019-08-13 21:12:37 +00:00
|
|
|
|
|
|
|
assert MastodonAPI.get_followers(user, %{"limit" => 1}) == [follower2_user]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "get_friends/2" do
|
|
|
|
test "returns user friends" do
|
|
|
|
user = insert(:user)
|
|
|
|
followed_one = insert(:user)
|
|
|
|
followed_two = insert(:user)
|
|
|
|
followed_three = insert(:user)
|
|
|
|
|
2020-12-01 20:17:52 +00:00
|
|
|
{:ok, user, followed_one} = User.follow(user, followed_one)
|
|
|
|
{:ok, user, followed_two} = User.follow(user, followed_two)
|
|
|
|
{:ok, user, followed_three} = User.follow(user, followed_three)
|
2019-08-13 21:12:37 +00:00
|
|
|
res = MastodonAPI.get_friends(user)
|
|
|
|
|
|
|
|
assert length(res) == 3
|
|
|
|
assert Enum.member?(res, refresh_record(followed_three))
|
|
|
|
assert Enum.member?(res, refresh_record(followed_two))
|
|
|
|
assert Enum.member?(res, refresh_record(followed_one))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "get_notifications/2" do
|
|
|
|
test "returns notifications for user" do
|
|
|
|
user = insert(:user)
|
|
|
|
subscriber = insert(:user)
|
|
|
|
|
|
|
|
User.subscribe(subscriber, user)
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
|
2019-08-31 07:20:34 +00:00
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, status1} = CommonAPI.post(user, %{status: "Magi"})
|
2019-08-13 21:12:37 +00:00
|
|
|
{:ok, [notification]} = Notification.create_notifications(status)
|
|
|
|
{:ok, [notification1]} = Notification.create_notifications(status1)
|
|
|
|
res = MastodonAPI.get_notifications(subscriber)
|
|
|
|
|
|
|
|
assert Enum.member?(Enum.map(res, & &1.id), notification.id)
|
|
|
|
assert Enum.member?(Enum.map(res, & &1.id), notification1.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "get_scheduled_activities/2" do
|
|
|
|
test "returns user scheduled activities" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
today =
|
|
|
|
NaiveDateTime.utc_now()
|
|
|
|
|> NaiveDateTime.add(:timer.minutes(6), :millisecond)
|
|
|
|
|> NaiveDateTime.to_iso8601()
|
|
|
|
|
|
|
|
attrs = %{params: %{}, scheduled_at: today}
|
|
|
|
{:ok, schedule} = ScheduledActivity.create(user, attrs)
|
|
|
|
assert MastodonAPI.get_scheduled_activities(user) == [schedule]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|