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.Conversation.ParticipationTest do
8 alias Pleroma.Conversation.Participation
9 alias Pleroma.Web.CommonAPI
11 test "it creates a participation for a conversation and a user" do
13 conversation = insert(:conversation)
15 {:ok, %Participation{} = participation} =
16 Participation.create_for_user_and_conversation(user, conversation)
18 assert participation.user_id == user.id
19 assert participation.conversation_id == conversation.id
22 # Creating again returns the same participation
23 {:ok, %Participation{} = participation_two} =
24 Participation.create_for_user_and_conversation(user, conversation)
26 assert participation.id == participation_two.id
27 refute participation.updated_at == participation_two.updated_at
30 test "recreating an existing participations sets it to unread" do
31 participation = insert(:participation, %{read: true})
33 {:ok, participation} =
34 Participation.create_for_user_and_conversation(
36 participation.conversation
39 refute participation.read
42 test "it marks a participation as read" do
43 participation = insert(:participation, %{read: false})
44 {:ok, participation} = Participation.mark_as_read(participation)
46 assert participation.read
49 test "it marks a participation as unread" do
50 participation = insert(:participation, %{read: true})
51 {:ok, participation} = Participation.mark_as_unread(participation)
53 refute participation.read
56 test "gets all the participations for a user, ordered by updated at descending" do
58 {:ok, activity_one} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
60 {:ok, activity_two} = CommonAPI.post(user, %{"status" => "x", "visibility" => "direct"})
63 {:ok, activity_three} =
64 CommonAPI.post(user, %{
66 "visibility" => "direct",
67 "in_reply_to_status_id" => activity_one.id
70 assert [participation_one, participation_two] = Participation.for_user(user)
72 object2 = Pleroma.Object.normalize(activity_two)
73 object3 = Pleroma.Object.normalize(activity_three)
75 assert participation_one.conversation.ap_id == object3.data["context"]
76 assert participation_two.conversation.ap_id == object2.data["context"]
79 assert [participation_one] = Participation.for_user(user, %{"limit" => 1})
81 assert participation_one.conversation.ap_id == object3.data["context"]
83 # With last_activity_id
84 assert [participation_one] =
85 Participation.for_user_with_last_activity_id(user, %{"limit" => 1})
87 assert participation_one.last_activity_id == activity_three.id