fixed User.unfollow with synchronization external user
authorMaksim Pechnikov <parallel588@gmail.com>
Fri, 16 Aug 2019 12:58:42 +0000 (15:58 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Fri, 16 Aug 2019 12:58:42 +0000 (15:58 +0300)
lib/pleroma/user.ex
test/user_test.exs

index a1040fe7165d2c2384d524adff923aa58dcc2689..23748ef26fca1d9ddd5dfdfc6e5dc540d75e6a84 100644 (file)
@@ -742,6 +742,7 @@ defmodule Pleroma.User do
     |> update_and_set_cache()
   end
 
+  @spec maybe_fetch_follow_information(User.t()) :: User.t()
   def maybe_fetch_follow_information(user) do
     with {:ok, user} <- fetch_follow_information(user) do
       user
@@ -799,9 +800,10 @@ defmodule Pleroma.User do
     end
   end
 
+  @spec maybe_update_following_count(User.t()) :: User.t()
   def maybe_update_following_count(%User{local: false} = user) do
     if Pleroma.Config.get([:instance, :external_user_synchronization]) do
-      {:ok, maybe_fetch_follow_information(user)}
+      maybe_fetch_follow_information(user)
     else
       user
     end
index b363b322c28590daac9a09375a9d11c7ed66d72c..3861cadacd2bb70b982f68dc4f1a9e6a25196fdb 100644 (file)
@@ -192,24 +192,64 @@ defmodule Pleroma.UserTest do
   #   assert websub
   # end
 
-  test "unfollow takes a user and another user" do
-    followed = insert(:user)
-    user = insert(:user, %{following: [User.ap_followers(followed)]})
+  describe "unfollow/2" do
+    setup do
+      setting = Pleroma.Config.get([:instance, :external_user_synchronization])
 
-    {:ok, user, _activity} = User.unfollow(user, followed)
+      on_exit(fn ->
+        Pleroma.Config.put([:instance, :external_user_synchronization], setting)
+      end)
 
-    user = User.get_cached_by_id(user.id)
+      :ok
+    end
 
-    assert user.following == []
-  end
+    test "unfollow with syncronizes external user" do
+      Pleroma.Config.put([:instance, :external_user_synchronization], true)
 
-  test "unfollow doesn't unfollow yourself" do
-    user = insert(:user)
+      followed =
+        insert(:user,
+          nickname: "fuser1",
+          follower_address: "http://localhost:4001/users/fuser1/followers",
+          following_address: "http://localhost:4001/users/fuser1/following",
+          ap_id: "http://localhost:4001/users/fuser1"
+        )
+
+      user =
+        insert(:user, %{
+          local: false,
+          nickname: "fuser2",
+          ap_id: "http://localhost:4001/users/fuser2",
+          follower_address: "http://localhost:4001/users/fuser2/followers",
+          following_address: "http://localhost:4001/users/fuser2/following",
+          following: [User.ap_followers(followed)]
+        })
 
-    {:error, _} = User.unfollow(user, user)
+      {:ok, user, _activity} = User.unfollow(user, followed)
 
-    user = User.get_cached_by_id(user.id)
-    assert user.following == [user.ap_id]
+      user = User.get_cached_by_id(user.id)
+
+      assert user.following == []
+    end
+
+    test "unfollow takes a user and another user" do
+      followed = insert(:user)
+      user = insert(:user, %{following: [User.ap_followers(followed)]})
+
+      {:ok, user, _activity} = User.unfollow(user, followed)
+
+      user = User.get_cached_by_id(user.id)
+
+      assert user.following == []
+    end
+
+    test "unfollow doesn't unfollow yourself" do
+      user = insert(:user)
+
+      {:error, _} = User.unfollow(user, user)
+
+      user = User.get_cached_by_id(user.id)
+      assert user.following == [user.ap_id]
+    end
   end
 
   test "test if a user is following another user" do