logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

user_relationship_test.exs (4892B)


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