Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.DatabaseTest do
  5. alias Pleroma.Repo
  6. alias Pleroma.User
  7. use Pleroma.DataCase
  8. import Pleroma.Factory
  9. setup_all do
  10. Mix.shell(Mix.Shell.Process)
  11. on_exit(fn ->
  12. Mix.shell(Mix.Shell.IO)
  13. end)
  14. :ok
  15. end
  16. describe "running update_users_following_followers_counts" do
  17. test "following and followers count are updated" do
  18. [user, user2] = insert_pair(:user)
  19. {:ok, %User{following: following, info: info} = user} = User.follow(user, user2)
  20. assert length(following) == 2
  21. assert info.follower_count == 0
  22. info_cng = Ecto.Changeset.change(info, %{follower_count: 3})
  23. {:ok, user} =
  24. user
  25. |> Ecto.Changeset.change(%{following: following ++ following})
  26. |> Ecto.Changeset.put_embed(:info, info_cng)
  27. |> Repo.update()
  28. assert length(user.following) == 4
  29. assert user.info.follower_count == 3
  30. assert :ok == Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"])
  31. user = User.get_by_id(user.id)
  32. assert length(user.following) == 2
  33. assert user.info.follower_count == 0
  34. end
  35. end
  36. end