logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

user_relationship_test.exs (4685B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.UserRelationshipTest do
  5. alias Pleroma.UserRelationship
  6. use Pleroma.DataCase
  7. import Pleroma.Factory
  8. describe "*_exists?/2" do
  9. setup do
  10. {:ok, users: insert_list(2, :user)}
  11. end
  12. test "returns false if record doesn't exist", %{users: [user1, user2]} do
  13. refute UserRelationship.block_exists?(user1, user2)
  14. refute UserRelationship.mute_exists?(user1, user2)
  15. refute UserRelationship.notification_mute_exists?(user1, user2)
  16. refute UserRelationship.reblog_mute_exists?(user1, user2)
  17. refute UserRelationship.inverse_subscription_exists?(user1, user2)
  18. end
  19. test "returns true if record exists", %{users: [user1, user2]} do
  20. for relationship_type <- [
  21. :block,
  22. :mute,
  23. :notification_mute,
  24. :reblog_mute,
  25. :inverse_subscription
  26. ] do
  27. insert(:user_relationship,
  28. source: user1,
  29. target: user2,
  30. relationship_type: relationship_type
  31. )
  32. end
  33. assert UserRelationship.block_exists?(user1, user2)
  34. assert UserRelationship.mute_exists?(user1, user2)
  35. assert UserRelationship.notification_mute_exists?(user1, user2)
  36. assert UserRelationship.reblog_mute_exists?(user1, user2)
  37. assert UserRelationship.inverse_subscription_exists?(user1, user2)
  38. end
  39. end
  40. describe "create_*/2" do
  41. setup do
  42. {:ok, users: insert_list(2, :user)}
  43. end
  44. test "creates user relationship record if it doesn't exist", %{users: [user1, user2]} do
  45. for relationship_type <- [
  46. :block,
  47. :mute,
  48. :notification_mute,
  49. :reblog_mute,
  50. :inverse_subscription
  51. ] do
  52. insert(:user_relationship,
  53. source: user1,
  54. target: user2,
  55. relationship_type: relationship_type
  56. )
  57. end
  58. UserRelationship.create_block(user1, user2)
  59. UserRelationship.create_mute(user1, user2)
  60. UserRelationship.create_notification_mute(user1, user2)
  61. UserRelationship.create_reblog_mute(user1, user2)
  62. UserRelationship.create_inverse_subscription(user1, user2)
  63. assert UserRelationship.block_exists?(user1, user2)
  64. assert UserRelationship.mute_exists?(user1, user2)
  65. assert UserRelationship.notification_mute_exists?(user1, user2)
  66. assert UserRelationship.reblog_mute_exists?(user1, user2)
  67. assert UserRelationship.inverse_subscription_exists?(user1, user2)
  68. end
  69. test "if record already exists, returns it", %{users: [user1, user2]} do
  70. user_block = UserRelationship.create_block(user1, user2)
  71. assert user_block == UserRelationship.create_block(user1, user2)
  72. end
  73. end
  74. describe "delete_*/2" do
  75. setup do
  76. {:ok, users: insert_list(2, :user)}
  77. end
  78. test "deletes user relationship record if it exists", %{users: [user1, user2]} do
  79. for relationship_type <- [
  80. :block,
  81. :mute,
  82. :notification_mute,
  83. :reblog_mute,
  84. :inverse_subscription
  85. ] do
  86. insert(:user_relationship,
  87. source: user1,
  88. target: user2,
  89. relationship_type: relationship_type
  90. )
  91. end
  92. assert {:ok, %UserRelationship{}} = UserRelationship.delete_block(user1, user2)
  93. assert {:ok, %UserRelationship{}} = UserRelationship.delete_mute(user1, user2)
  94. assert {:ok, %UserRelationship{}} = UserRelationship.delete_notification_mute(user1, user2)
  95. assert {:ok, %UserRelationship{}} = UserRelationship.delete_reblog_mute(user1, user2)
  96. assert {:ok, %UserRelationship{}} =
  97. UserRelationship.delete_inverse_subscription(user1, user2)
  98. refute UserRelationship.block_exists?(user1, user2)
  99. refute UserRelationship.mute_exists?(user1, user2)
  100. refute UserRelationship.notification_mute_exists?(user1, user2)
  101. refute UserRelationship.reblog_mute_exists?(user1, user2)
  102. refute UserRelationship.inverse_subscription_exists?(user1, user2)
  103. end
  104. test "if record does not exist, returns {:ok, nil}", %{users: [user1, user2]} do
  105. assert {:ok, nil} = UserRelationship.delete_block(user1, user2)
  106. assert {:ok, nil} = UserRelationship.delete_mute(user1, user2)
  107. assert {:ok, nil} = UserRelationship.delete_notification_mute(user1, user2)
  108. assert {:ok, nil} = UserRelationship.delete_reblog_mute(user1, user2)
  109. assert {:ok, nil} = UserRelationship.delete_inverse_subscription(user1, user2)
  110. end
  111. end
  112. end