logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

mastodon_api_test.exs (3335B)


  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. defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.Notification
  7. alias Pleroma.ScheduledActivity
  8. alias Pleroma.User
  9. alias Pleroma.Web.CommonAPI
  10. alias Pleroma.Web.MastodonAPI.MastodonAPI
  11. import Pleroma.Factory
  12. describe "follow/3" do
  13. test "returns error when followed user is deactivated" do
  14. follower = insert(:user)
  15. user = insert(:user, local: true, deactivated: true)
  16. assert {:error, _error} = MastodonAPI.follow(follower, user)
  17. end
  18. test "following for user" do
  19. follower = insert(:user)
  20. user = insert(:user)
  21. {:ok, follower} = MastodonAPI.follow(follower, user)
  22. assert User.following?(follower, user)
  23. end
  24. test "returns ok if user already followed" do
  25. follower = insert(:user)
  26. user = insert(:user)
  27. {:ok, follower} = User.follow(follower, user)
  28. {:ok, follower} = MastodonAPI.follow(follower, refresh_record(user))
  29. assert User.following?(follower, user)
  30. end
  31. end
  32. describe "get_followers/2" do
  33. test "returns user followers" do
  34. follower1_user = insert(:user)
  35. follower2_user = insert(:user)
  36. user = insert(:user)
  37. {:ok, _follower1_user} = User.follow(follower1_user, user)
  38. {:ok, follower2_user} = User.follow(follower2_user, user)
  39. assert MastodonAPI.get_followers(user, %{"limit" => 1}) == [follower2_user]
  40. end
  41. end
  42. describe "get_friends/2" do
  43. test "returns user friends" do
  44. user = insert(:user)
  45. followed_one = insert(:user)
  46. followed_two = insert(:user)
  47. followed_three = insert(:user)
  48. {:ok, user} = User.follow(user, followed_one)
  49. {:ok, user} = User.follow(user, followed_two)
  50. {:ok, user} = User.follow(user, followed_three)
  51. res = MastodonAPI.get_friends(user)
  52. assert length(res) == 3
  53. assert Enum.member?(res, refresh_record(followed_three))
  54. assert Enum.member?(res, refresh_record(followed_two))
  55. assert Enum.member?(res, refresh_record(followed_one))
  56. end
  57. end
  58. describe "get_notifications/2" do
  59. test "returns notifications for user" do
  60. user = insert(:user)
  61. subscriber = insert(:user)
  62. User.subscribe(subscriber, user)
  63. {:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
  64. {:ok, status1} = CommonAPI.post(user, %{status: "Magi"})
  65. {:ok, [notification]} = Notification.create_notifications(status)
  66. {:ok, [notification1]} = Notification.create_notifications(status1)
  67. res = MastodonAPI.get_notifications(subscriber)
  68. assert Enum.member?(Enum.map(res, & &1.id), notification.id)
  69. assert Enum.member?(Enum.map(res, & &1.id), notification1.id)
  70. end
  71. end
  72. describe "get_scheduled_activities/2" do
  73. test "returns user scheduled activities" do
  74. user = insert(:user)
  75. today =
  76. NaiveDateTime.utc_now()
  77. |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
  78. |> NaiveDateTime.to_iso8601()
  79. attrs = %{params: %{}, scheduled_at: today}
  80. {:ok, schedule} = ScheduledActivity.create(user, attrs)
  81. assert MastodonAPI.get_scheduled_activities(user) == [schedule]
  82. end
  83. end
  84. end