Check if mogrify available before calling it
[akkoma] / test / web / mastodon_api / mastodon_api_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
6 use Pleroma.Web.ConnCase
7
8 alias Pleroma.Notification
9 alias Pleroma.ScheduledActivity
10 alias Pleroma.User
11 alias Pleroma.Web.CommonAPI
12 alias Pleroma.Web.MastodonAPI.MastodonAPI
13
14 import Pleroma.Factory
15
16 describe "follow/3" do
17 test "returns error when followed user is deactivated" do
18 follower = insert(:user)
19 user = insert(:user, local: true, deactivated: true)
20 {:error, error} = MastodonAPI.follow(follower, user)
21 assert error == :rejected
22 end
23
24 test "following for user" do
25 follower = insert(:user)
26 user = insert(:user)
27 {:ok, follower} = MastodonAPI.follow(follower, user)
28 assert User.following?(follower, user)
29 end
30
31 test "returns ok if user already followed" do
32 follower = insert(:user)
33 user = insert(:user)
34 {:ok, follower} = User.follow(follower, user)
35 {:ok, follower} = MastodonAPI.follow(follower, refresh_record(user))
36 assert User.following?(follower, user)
37 end
38 end
39
40 describe "get_followers/2" do
41 test "returns user followers" do
42 follower1_user = insert(:user)
43 follower2_user = insert(:user)
44 user = insert(:user)
45 {:ok, _follower1_user} = User.follow(follower1_user, user)
46 {:ok, follower2_user} = User.follow(follower2_user, user)
47
48 assert MastodonAPI.get_followers(user, %{"limit" => 1}) == [follower2_user]
49 end
50 end
51
52 describe "get_friends/2" do
53 test "returns user friends" do
54 user = insert(:user)
55 followed_one = insert(:user)
56 followed_two = insert(:user)
57 followed_three = insert(:user)
58
59 {:ok, user} = User.follow(user, followed_one)
60 {:ok, user} = User.follow(user, followed_two)
61 {:ok, user} = User.follow(user, followed_three)
62 res = MastodonAPI.get_friends(user)
63
64 assert length(res) == 3
65 assert Enum.member?(res, refresh_record(followed_three))
66 assert Enum.member?(res, refresh_record(followed_two))
67 assert Enum.member?(res, refresh_record(followed_one))
68 end
69 end
70
71 describe "get_notifications/2" do
72 test "returns notifications for user" do
73 user = insert(:user)
74 subscriber = insert(:user)
75
76 User.subscribe(subscriber, user)
77
78 {:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
79
80 {:ok, status1} = CommonAPI.post(user, %{status: "Magi"})
81 {:ok, [notification]} = Notification.create_notifications(status)
82 {:ok, [notification1]} = Notification.create_notifications(status1)
83 res = MastodonAPI.get_notifications(subscriber)
84
85 assert Enum.member?(Enum.map(res, & &1.id), notification.id)
86 assert Enum.member?(Enum.map(res, & &1.id), notification1.id)
87 end
88 end
89
90 describe "get_scheduled_activities/2" do
91 test "returns user scheduled activities" do
92 user = insert(:user)
93
94 today =
95 NaiveDateTime.utc_now()
96 |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
97 |> NaiveDateTime.to_iso8601()
98
99 attrs = %{params: %{}, scheduled_at: today}
100 {:ok, schedule} = ScheduledActivity.create(user, attrs)
101 assert MastodonAPI.get_scheduled_activities(user) == [schedule]
102 end
103 end
104 end