Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/unfollow...
[akkoma] / test / web / twitter_api / twitter_api_test.exs
index 9e843e877716f5b3edf0ec7ecdd2a4983d31500d..590428423b2e3a23e97476c3cfba61d572be328b 100644 (file)
@@ -102,6 +102,17 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: direct_activity_user, mentioned: [user]})
   end
 
+  test "fetch user's mentions" do
+    user = insert(:user)
+    {:ok, activity} = ActivityBuilder.insert(%{"to" => [user.ap_id]})
+    activity_user = Repo.get_by(User, ap_id: activity.data["actor"])
+
+    statuses = TwitterAPI.fetch_mentions(user)
+
+    assert length(statuses) == 1
+    assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user, mentioned: [user]})
+  end
+
   test "get a user by params" do
     user1_result = {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"})
     {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"})
@@ -144,28 +155,48 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
     assert status == ActivityRepresenter.to_map(activity, %{for: user, user: actor})
   end
 
-  test "Follow another user" do
+  test "Follow another user using user_id" do
     user = insert(:user)
-    following = insert(:user)
+    followed = insert(:user)
 
-    {:ok, user, following, activity } = TwitterAPI.follow(user, following.id)
+    {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
+    assert user.following == [User.ap_followers(followed)]
 
-    user = Repo.get(User, user.id)
-    follow = Repo.get(Activity, activity.id)
+    { :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id})
+    assert msg == "Could not follow user: #{followed.nickname} is already on your list."
+  end
 
-    assert user.following == [User.ap_followers(following)]
-    assert follow == activity
+  test "Follow another user using screen_name" do
+    user = insert(:user)
+    followed = insert(:user)
+
+    {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
+    assert user.following == [User.ap_followers(followed)]
+
+    { :error, msg } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
+    assert msg == "Could not follow user: #{followed.nickname} is already on your list."
   end
 
-  test "Unfollow another user" do
-    following = insert(:user)
-    user = insert(:user, %{following: [User.ap_followers(following)]})
+  test "Unfollow another user using user_id" do
+    unfollowed = insert(:user)
+    user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
 
-    {:ok, user, _following } = TwitterAPI.unfollow(user, following.id)
+    {:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
+    assert user.following == []
 
-    user = Repo.get(User, user.id)
+    { :error, msg } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
+    assert msg == "Not subscribed!"
+  end
+
+  test "Unfollow another user using screen_name" do
+    unfollowed = insert(:user)
+    user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
 
+    {:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
     assert user.following == []
+
+    { :error, msg } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
+    assert msg == "Not subscribed!"
   end
 
   test "fetch statuses in a context using the conversation id" do
@@ -284,8 +315,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
   end
 
   setup do
-    Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
-    Supervisor.restart_child(Pleroma.Supervisor, ConCache)
+    Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
+    Supervisor.restart_child(Pleroma.Supervisor, Cachex)
     :ok
   end
 end