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 Pleroma.UserRelationshipTest do
6 alias Pleroma.UserRelationship
10 import Pleroma.Factory
12 describe "*_exists?/2" do
14 {:ok, users: insert_list(2, :user)}
17 test "returns false if record doesn't exist", %{users: [user1, user2]} do
18 refute UserRelationship.block_exists?(user1, user2)
19 refute UserRelationship.mute_exists?(user1, user2)
20 refute UserRelationship.notification_mute_exists?(user1, user2)
21 refute UserRelationship.reblog_mute_exists?(user1, user2)
22 refute UserRelationship.inverse_subscription_exists?(user1, user2)
25 test "returns true if record exists", %{users: [user1, user2]} do
26 for relationship_type <- [
33 insert(:user_relationship,
36 relationship_type: relationship_type
40 assert UserRelationship.block_exists?(user1, user2)
41 assert UserRelationship.mute_exists?(user1, user2)
42 assert UserRelationship.notification_mute_exists?(user1, user2)
43 assert UserRelationship.reblog_mute_exists?(user1, user2)
44 assert UserRelationship.inverse_subscription_exists?(user1, user2)
48 describe "create_*/2" do
50 {:ok, users: insert_list(2, :user)}
53 test "creates user relationship record if it doesn't exist", %{users: [user1, user2]} do
54 for relationship_type <- [
61 insert(:user_relationship,
64 relationship_type: relationship_type
68 UserRelationship.create_block(user1, user2)
69 UserRelationship.create_mute(user1, user2)
70 UserRelationship.create_notification_mute(user1, user2)
71 UserRelationship.create_reblog_mute(user1, user2)
72 UserRelationship.create_inverse_subscription(user1, user2)
74 assert UserRelationship.block_exists?(user1, user2)
75 assert UserRelationship.mute_exists?(user1, user2)
76 assert UserRelationship.notification_mute_exists?(user1, user2)
77 assert UserRelationship.reblog_mute_exists?(user1, user2)
78 assert UserRelationship.inverse_subscription_exists?(user1, user2)
81 test "if record already exists, returns it", %{users: [user1, user2]} do
82 user_block = UserRelationship.create_block(user1, user2)
83 assert user_block == UserRelationship.create_block(user1, user2)
87 describe "delete_*/2" do
89 {:ok, users: insert_list(2, :user)}
92 test "deletes user relationship record if it exists", %{users: [user1, user2]} do
93 for relationship_type <- [
100 insert(:user_relationship,
103 relationship_type: relationship_type
107 assert {:ok, %UserRelationship{}} = UserRelationship.delete_block(user1, user2)
108 assert {:ok, %UserRelationship{}} = UserRelationship.delete_mute(user1, user2)
109 assert {:ok, %UserRelationship{}} = UserRelationship.delete_notification_mute(user1, user2)
110 assert {:ok, %UserRelationship{}} = UserRelationship.delete_reblog_mute(user1, user2)
112 assert {:ok, %UserRelationship{}} =
113 UserRelationship.delete_inverse_subscription(user1, user2)
115 refute UserRelationship.block_exists?(user1, user2)
116 refute UserRelationship.mute_exists?(user1, user2)
117 refute UserRelationship.notification_mute_exists?(user1, user2)
118 refute UserRelationship.reblog_mute_exists?(user1, user2)
119 refute UserRelationship.inverse_subscription_exists?(user1, user2)
122 test "if record does not exist, returns {:ok, nil}", %{users: [user1, user2]} do
123 assert {:ok, nil} = UserRelationship.delete_block(user1, user2)
124 assert {:ok, nil} = UserRelationship.delete_mute(user1, user2)
125 assert {:ok, nil} = UserRelationship.delete_notification_mute(user1, user2)
126 assert {:ok, nil} = UserRelationship.delete_reblog_mute(user1, user2)
127 assert {:ok, nil} = UserRelationship.delete_inverse_subscription(user1, user2)