2019-11-20 05:46:11 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-11-20 05:46:11 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.UserRelationshipTest do
|
|
|
|
alias Pleroma.UserRelationship
|
|
|
|
|
2022-08-24 09:24:07 -06:00
|
|
|
use Pleroma.DataCase, async: false
|
2019-11-20 05:46:11 -07:00
|
|
|
|
2022-08-24 09:24:07 -06:00
|
|
|
import Mock
|
2019-11-20 05:46:11 -07:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
describe "*_exists?/2" do
|
|
|
|
setup do
|
|
|
|
{:ok, users: insert_list(2, :user)}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns false if record doesn't exist", %{users: [user1, user2]} do
|
|
|
|
refute UserRelationship.block_exists?(user1, user2)
|
|
|
|
refute UserRelationship.mute_exists?(user1, user2)
|
|
|
|
refute UserRelationship.notification_mute_exists?(user1, user2)
|
|
|
|
refute UserRelationship.reblog_mute_exists?(user1, user2)
|
|
|
|
refute UserRelationship.inverse_subscription_exists?(user1, user2)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns true if record exists", %{users: [user1, user2]} do
|
|
|
|
for relationship_type <- [
|
|
|
|
:block,
|
|
|
|
:mute,
|
|
|
|
:notification_mute,
|
|
|
|
:reblog_mute,
|
|
|
|
:inverse_subscription
|
|
|
|
] do
|
|
|
|
insert(:user_relationship,
|
|
|
|
source: user1,
|
|
|
|
target: user2,
|
|
|
|
relationship_type: relationship_type
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert UserRelationship.block_exists?(user1, user2)
|
|
|
|
assert UserRelationship.mute_exists?(user1, user2)
|
|
|
|
assert UserRelationship.notification_mute_exists?(user1, user2)
|
|
|
|
assert UserRelationship.reblog_mute_exists?(user1, user2)
|
|
|
|
assert UserRelationship.inverse_subscription_exists?(user1, user2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "create_*/2" do
|
|
|
|
setup do
|
|
|
|
{:ok, users: insert_list(2, :user)}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creates user relationship record if it doesn't exist", %{users: [user1, user2]} do
|
|
|
|
for relationship_type <- [
|
|
|
|
:block,
|
|
|
|
:mute,
|
|
|
|
:notification_mute,
|
|
|
|
:reblog_mute,
|
|
|
|
:inverse_subscription
|
|
|
|
] do
|
|
|
|
insert(:user_relationship,
|
|
|
|
source: user1,
|
|
|
|
target: user2,
|
|
|
|
relationship_type: relationship_type
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
UserRelationship.create_block(user1, user2)
|
|
|
|
UserRelationship.create_mute(user1, user2)
|
|
|
|
UserRelationship.create_notification_mute(user1, user2)
|
|
|
|
UserRelationship.create_reblog_mute(user1, user2)
|
|
|
|
UserRelationship.create_inverse_subscription(user1, user2)
|
|
|
|
|
|
|
|
assert UserRelationship.block_exists?(user1, user2)
|
|
|
|
assert UserRelationship.mute_exists?(user1, user2)
|
|
|
|
assert UserRelationship.notification_mute_exists?(user1, user2)
|
|
|
|
assert UserRelationship.reblog_mute_exists?(user1, user2)
|
|
|
|
assert UserRelationship.inverse_subscription_exists?(user1, user2)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "if record already exists, returns it", %{users: [user1, user2]} do
|
2022-08-24 09:24:07 -06:00
|
|
|
user_block =
|
|
|
|
with_mock NaiveDateTime, [:passthrough], utc_now: fn -> ~N[2017-03-17 17:09:58] end do
|
|
|
|
{:ok, %{inserted_at: ~N[2017-03-17 17:09:58]}} =
|
|
|
|
UserRelationship.create_block(user1, user2)
|
|
|
|
end
|
|
|
|
|
2019-11-20 05:46:11 -07:00
|
|
|
assert user_block == UserRelationship.create_block(user1, user2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "delete_*/2" do
|
|
|
|
setup do
|
|
|
|
{:ok, users: insert_list(2, :user)}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes user relationship record if it exists", %{users: [user1, user2]} do
|
|
|
|
for relationship_type <- [
|
|
|
|
:block,
|
|
|
|
:mute,
|
|
|
|
:notification_mute,
|
|
|
|
:reblog_mute,
|
|
|
|
:inverse_subscription
|
|
|
|
] do
|
|
|
|
insert(:user_relationship,
|
|
|
|
source: user1,
|
|
|
|
target: user2,
|
|
|
|
relationship_type: relationship_type
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert {:ok, %UserRelationship{}} = UserRelationship.delete_block(user1, user2)
|
|
|
|
assert {:ok, %UserRelationship{}} = UserRelationship.delete_mute(user1, user2)
|
|
|
|
assert {:ok, %UserRelationship{}} = UserRelationship.delete_notification_mute(user1, user2)
|
|
|
|
assert {:ok, %UserRelationship{}} = UserRelationship.delete_reblog_mute(user1, user2)
|
|
|
|
|
|
|
|
assert {:ok, %UserRelationship{}} =
|
|
|
|
UserRelationship.delete_inverse_subscription(user1, user2)
|
|
|
|
|
|
|
|
refute UserRelationship.block_exists?(user1, user2)
|
|
|
|
refute UserRelationship.mute_exists?(user1, user2)
|
|
|
|
refute UserRelationship.notification_mute_exists?(user1, user2)
|
|
|
|
refute UserRelationship.reblog_mute_exists?(user1, user2)
|
|
|
|
refute UserRelationship.inverse_subscription_exists?(user1, user2)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "if record does not exist, returns {:ok, nil}", %{users: [user1, user2]} do
|
|
|
|
assert {:ok, nil} = UserRelationship.delete_block(user1, user2)
|
|
|
|
assert {:ok, nil} = UserRelationship.delete_mute(user1, user2)
|
|
|
|
assert {:ok, nil} = UserRelationship.delete_notification_mute(user1, user2)
|
|
|
|
assert {:ok, nil} = UserRelationship.delete_reblog_mute(user1, user2)
|
|
|
|
assert {:ok, nil} = UserRelationship.delete_inverse_subscription(user1, user2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|