Commit f36724ef authored by lain's avatar lain

User: Never return nil for user follower counts.

parent 139b1fed
Pipeline #20506 passed with stages
in 16 minutes and 28 seconds
...@@ -178,8 +178,8 @@ def ap_following(%User{following_address: fa}) when is_binary(fa), do: fa ...@@ -178,8 +178,8 @@ def ap_following(%User{following_address: fa}) when is_binary(fa), do: fa
def ap_following(%User{} = user), do: "#{ap_id(user)}/following" def ap_following(%User{} = user), do: "#{ap_id(user)}/following"
def user_info(%User{} = user, args \\ %{}) do def user_info(%User{} = user, args \\ %{}) do
following_count = Map.get(args, :following_count, user.following_count) following_count = Map.get(args, :following_count, user.following_count) || 0
follower_count = Map.get(args, :follower_count, user.follower_count) follower_count = Map.get(args, :follower_count, user.follower_count) || 0
%{ %{
note_count: user.note_count, note_count: user.note_count,
......
...@@ -1347,6 +1347,14 @@ test "follower count is updated when a follower is blocked" do ...@@ -1347,6 +1347,14 @@ test "follower count is updated when a follower is blocked" do
assert User.user_info(user).follower_count == 2 assert User.user_info(user).follower_count == 2
end end
test "with nil follower count fields, 0 will be returned" do
user = insert(:user, follower_count: nil, following_count: nil)
user_info = User.user_info(user)
assert user_info.follower_count == 0
assert user_info.following_count == 0
end
describe "list_inactive_users_query/1" do describe "list_inactive_users_query/1" do
defp days_ago(days) do defp days_ago(days) do
NaiveDateTime.add( NaiveDateTime.add(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment