X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fconversation%2Fparticipation_test.exs;h=59a1b6492d75df3e0924e69a1c5183c1522686dc;hb=e4b12494d77e7a6920a408d62d5b8fe0f886a14d;hp=863270022e8c0f8ac8675277114642cc46498598;hpb=1fc591fcfc1c9a335928b85d5a56b004346f2826;p=akkoma
diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs
index 863270022..59a1b6492 100644
--- a/test/conversation/participation_test.exs
+++ b/test/conversation/participation_test.exs
@@ -1,11 +1,13 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Conversation.ParticipationTest do
use Pleroma.DataCase
import Pleroma.Factory
+ alias Pleroma.Conversation
alias Pleroma.Conversation.Participation
+ alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
@@ -14,7 +16,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
other_user = insert(:user)
{:ok, _activity} =
- CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hey @#{other_user.nickname}.", visibility: "direct"})
[participation] = Participation.for_user(user)
@@ -28,7 +30,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
other_user = insert(:user)
{:ok, _} =
- CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hey @#{other_user.nickname}.", visibility: "direct"})
user = User.get_cached_by_id(user.id)
other_user = User.get_cached_by_id(other_user.id)
@@ -41,9 +43,9 @@ defmodule Pleroma.Conversation.ParticipationTest do
{:ok, _} =
CommonAPI.post(other_user, %{
- "status" => "Hey @#{user.nickname}.",
- "visibility" => "direct",
- "in_reply_to_conversation_id" => participation.id
+ status: "Hey @#{user.nickname}.",
+ visibility: "direct",
+ in_reply_to_conversation_id: participation.id
})
user = User.get_cached_by_id(user.id)
@@ -62,7 +64,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
third_user = insert(:user)
{:ok, activity} =
- CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+ CommonAPI.post(user, %{status: "Hey @#{other_user.nickname}.", visibility: "direct"})
user = User.get_cached_by_id(user.id)
other_user = User.get_cached_by_id(other_user.id)
@@ -77,9 +79,9 @@ defmodule Pleroma.Conversation.ParticipationTest do
{:ok, _activity} =
CommonAPI.post(user, %{
- "in_reply_to_status_id" => activity.id,
- "status" => "Hey @#{third_user.nickname}.",
- "visibility" => "direct"
+ in_reply_to_status_id: activity.id,
+ status: "Hey @#{third_user.nickname}.",
+ visibility: "direct"
})
[participation] = Participation.for_user(user)
@@ -98,7 +100,9 @@ defmodule Pleroma.Conversation.ParticipationTest do
assert participation.user_id == user.id
assert participation.conversation_id == conversation.id
+ # Needed because updated_at is accurate down to a second
:timer.sleep(1000)
+
# Creating again returns the same participation
{:ok, %Participation{} = participation_two} =
Participation.create_for_user_and_conversation(user, conversation)
@@ -121,9 +125,10 @@ defmodule Pleroma.Conversation.ParticipationTest do
test "it marks a participation as read" do
participation = insert(:participation, %{read: false})
- {:ok, participation} = Participation.mark_as_read(participation)
+ {:ok, updated_participation} = Participation.mark_as_read(participation)
- assert participation.read
+ assert updated_participation.read
+ assert updated_participation.updated_at == participation.updated_at
end
test "it marks a participation as unread" do
@@ -149,18 +154,27 @@ defmodule Pleroma.Conversation.ParticipationTest do
test "gets all the participations for a user, ordered by updated at descending" do
user = insert(:user)
- {:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
- :timer.sleep(1000)
- {:ok, activity_two} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
- :timer.sleep(1000)
+ {:ok, activity_one} = CommonAPI.post(user, %{status: "x", visibility: "direct"})
+ {:ok, activity_two} = CommonAPI.post(user, %{status: "x", visibility: "direct"})
{:ok, activity_three} =
CommonAPI.post(user, %{
- "status" => "x",
- "visibility" => "direct",
- "in_reply_to_status_id" => activity_one.id
+ status: "x",
+ visibility: "direct",
+ in_reply_to_status_id: activity_one.id
})
+ # Offset participations because the accuracy of updated_at is down to a second
+
+ for {activity, offset} <- [{activity_two, 1}, {activity_three, 2}] do
+ conversation = Conversation.get_for_ap_id(activity.data["context"])
+ participation = Participation.for_user_and_conversation(user, conversation)
+ updated_at = NaiveDateTime.add(Map.get(participation, :updated_at), offset)
+
+ Ecto.Changeset.change(participation, %{updated_at: updated_at})
+ |> Repo.update!()
+ end
+
assert [participation_one, participation_two] = Participation.for_user(user)
object2 = Pleroma.Object.normalize(activity_two)
@@ -187,7 +201,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
test "Doesn't die when the conversation gets empty" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
[participation] = Participation.for_user_with_last_activity_id(user)
assert participation.last_activity_id == activity.id
@@ -201,7 +215,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
user = insert(:user)
other_user = insert(:user)
- {:ok, _activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, _activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
[participation] = Participation.for_user_with_last_activity_id(user)
participation = Repo.preload(participation, :recipients)
@@ -225,26 +239,26 @@ defmodule Pleroma.Conversation.ParticipationTest do
{:ok, _direct1} =
CommonAPI.post(third_user, %{
- "status" => "Hi @#{blocker.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}",
+ visibility: "direct"
})
{:ok, _direct2} =
CommonAPI.post(third_user, %{
- "status" => "Hi @#{blocker.nickname}, @#{blocked.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}, @#{blocked.nickname}",
+ visibility: "direct"
})
{:ok, _direct3} =
CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}",
+ visibility: "direct"
})
{:ok, _direct4} =
CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}, @#{third_user.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}, @#{third_user.nickname}",
+ visibility: "direct"
})
assert [%{read: false}, %{read: false}, %{read: false}, %{read: false}] =
@@ -252,7 +266,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 4
- {:ok, blocker} = User.block(blocker, blocked)
+ {:ok, _user_relationship} = User.block(blocker, blocked)
# The conversations with the blocked user are marked as read
assert [%{read: true}, %{read: true}, %{read: true}, %{read: false}] =
@@ -274,13 +288,13 @@ defmodule Pleroma.Conversation.ParticipationTest do
blocked = insert(:user)
third_user = insert(:user)
- {:ok, blocker} = User.block(blocker, blocked)
+ {:ok, _user_relationship} = User.block(blocker, blocked)
# When the blocked user is the author
{:ok, _direct1} =
CommonAPI.post(blocked, %{
- "status" => "Hi @#{blocker.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}",
+ visibility: "direct"
})
assert [%{read: true}] = Participation.for_user(blocker)
@@ -289,8 +303,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
# When the blocked user is a recipient
{:ok, _direct2} =
CommonAPI.post(third_user, %{
- "status" => "Hi @#{blocker.nickname}, @#{blocked.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{blocker.nickname}, @#{blocked.nickname}",
+ visibility: "direct"
})
assert [%{read: true}, %{read: true}] = Participation.for_user(blocker)
@@ -307,11 +321,11 @@ defmodule Pleroma.Conversation.ParticipationTest do
{:ok, _direct1} =
CommonAPI.post(blocker, %{
- "status" => "Hi @#{third_user.nickname}, @#{blocked.nickname}",
- "visibility" => "direct"
+ status: "Hi @#{third_user.nickname}, @#{blocked.nickname}",
+ visibility: "direct"
})
- {:ok, blocker} = User.block(blocker, blocked)
+ {:ok, _user_relationship} = User.block(blocker, blocked)
assert [%{read: true}] = Participation.for_user(blocker)
assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
@@ -320,9 +334,9 @@ defmodule Pleroma.Conversation.ParticipationTest do
# When it's a reply from the blocked user
{:ok, _direct2} =
CommonAPI.post(blocked, %{
- "status" => "reply",
- "visibility" => "direct",
- "in_reply_to_conversation_id" => blocked_participation.id
+ status: "reply",
+ visibility: "direct",
+ in_reply_to_conversation_id: blocked_participation.id
})
assert [%{read: true}] = Participation.for_user(blocker)
@@ -333,9 +347,9 @@ defmodule Pleroma.Conversation.ParticipationTest do
# When it's a reply from the third user
{:ok, _direct3} =
CommonAPI.post(third_user, %{
- "status" => "reply",
- "visibility" => "direct",
- "in_reply_to_conversation_id" => third_user_participation.id
+ status: "reply",
+ visibility: "direct",
+ in_reply_to_conversation_id: third_user_participation.id
})
assert [%{read: true}] = Participation.for_user(blocker)