2019-08-13 15:12:37 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 15:44:49 -07:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-08-13 15:12:37 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
|
|
|
|
alias Pleroma.Notification
|
|
|
|
alias Pleroma.ScheduledActivity
|
|
|
|
alias Pleroma.User
|
2019-08-31 01:20:34 -06:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-08-13 15:12:37 -06:00
|
|
|
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
describe "follow/3" do
|
2019-10-16 12:59:21 -06:00
|
|
|
test "returns error when followed user is deactivated" do
|
2019-08-13 15:12:37 -06:00
|
|
|
follower = insert(:user)
|
2019-10-16 12:59:21 -06:00
|
|
|
user = insert(:user, local: true, deactivated: true)
|
2020-08-04 07:08:51 -06:00
|
|
|
assert {:error, _error} = MastodonAPI.follow(follower, user)
|
2019-08-13 15:12:37 -06: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 13:17:52 -07:00
|
|
|
{:ok, follower, user} = User.follow(follower, user)
|
2019-08-13 15:12:37 -06: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 13:17:52 -07:00
|
|
|
{:ok, _follower1_user, _user} = User.follow(follower1_user, user)
|
|
|
|
{:ok, follower2_user, _user} = User.follow(follower2_user, user)
|
2019-08-13 15:12:37 -06: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 13:17:52 -07: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 15:12:37 -06: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 13:59:26 -06:00
|
|
|
{:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
|
2019-08-31 01:20:34 -06:00
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, status1} = CommonAPI.post(user, %{status: "Magi"})
|
2019-08-13 15:12:37 -06: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
|