1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.DatabaseTest do
10 import Pleroma.Factory
13 Mix.shell(Mix.Shell.Process)
16 Mix.shell(Mix.Shell.IO)
22 describe "running update_users_following_followers_counts" do
23 test "following and followers count are updated" do
24 [user, user2] = insert_pair(:user)
25 {:ok, %User{following: following, info: info} = user} = User.follow(user, user2)
27 assert length(following) == 2
28 assert info.follower_count == 0
30 info_cng = Ecto.Changeset.change(info, %{follower_count: 3})
34 |> Ecto.Changeset.change(%{following: following ++ following})
35 |> Ecto.Changeset.put_embed(:info, info_cng)
38 assert length(user.following) == 4
39 assert user.info.follower_count == 3
41 assert :ok == Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"])
43 user = User.get_by_id(user.id)
45 assert length(user.following) == 2
46 assert user.info.follower_count == 0