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.

90 lines
2.4KB

  1. defmodule Pleroma.UserTest do
  2. alias Pleroma.Builders.UserBuilder
  3. alias Pleroma.User
  4. use Pleroma.DataCase
  5. import Pleroma.Factory
  6. test "ap_id returns the activity pub id for the user" do
  7. host =
  8. Application.get_env(:pleroma, Pleroma.Web.Endpoint)
  9. |> Keyword.fetch!(:url)
  10. |> Keyword.fetch!(:host)
  11. user = UserBuilder.build
  12. expected_ap_id = "https://#{host}/users/#{user.nickname}"
  13. assert expected_ap_id == User.ap_id(user)
  14. end
  15. test "ap_followers returns the followers collection for the user" do
  16. user = UserBuilder.build
  17. expected_followers_collection = "#{User.ap_id(user)}/followers"
  18. assert expected_followers_collection == User.ap_followers(user)
  19. end
  20. test "follow takes a user and another user" do
  21. user = insert(:user)
  22. followed = insert(:user)
  23. {:ok, user } = User.follow(user, followed)
  24. user = Repo.get(User, user.id)
  25. assert user.following == [User.ap_followers(followed)]
  26. end
  27. test "unfollow takes a user and another user" do
  28. followed = insert(:user)
  29. user = insert(:user, %{following: [User.ap_followers(followed)]})
  30. {:ok, user } = User.unfollow(user, followed)
  31. user = Repo.get(User, user.id)
  32. assert user.following == []
  33. end
  34. test "test if a user is following another user" do
  35. followed = insert(:user)
  36. user = insert(:user, %{following: [User.ap_followers(followed)]})
  37. assert User.following?(user, followed)
  38. refute User.following?(followed, user)
  39. end
  40. describe "user registration" do
  41. @full_user_data %{
  42. bio: "A guy",
  43. name: "my name",
  44. nickname: "nick",
  45. password: "test",
  46. password_confirmation: "test",
  47. email: "email@example.com"
  48. }
  49. test "it requires a bio, email, name, nickname and password" do
  50. @full_user_data
  51. |> Map.keys
  52. |> Enum.each(fn (key) ->
  53. params = Map.delete(@full_user_data, key)
  54. changeset = User.register_changeset(%User{}, params)
  55. assert changeset.valid? == false
  56. end)
  57. end
  58. test "it sets the password_hash, ap_id and following fields" do
  59. changeset = User.register_changeset(%User{}, @full_user_data)
  60. assert changeset.valid?
  61. assert is_binary(changeset.changes[:password_hash])
  62. assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
  63. assert changeset.changes[:following] == [User.ap_followers(%User{nickname: @full_user_data.nickname})]
  64. end
  65. end
  66. end