1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ActivityTest do
9 alias Pleroma.ThreadMute
10 import Pleroma.Factory
12 test "returns an activity by it's AP id" do
13 activity = insert(:note_activity)
14 found_activity = Activity.get_by_ap_id(activity.data["id"])
16 assert activity == found_activity
19 test "returns activities by it's objects AP ids" do
20 activity = insert(:note_activity)
21 [found_activity] = Activity.get_all_create_by_object_ap_id(activity.data["object"]["id"])
23 assert activity == found_activity
26 test "returns the activity that created an object" do
27 activity = insert(:note_activity)
29 found_activity = Activity.get_create_by_object_ap_id(activity.data["object"]["id"])
31 assert activity == found_activity
34 test "preloading a bookmark" do
38 activity = insert(:note_activity)
39 {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
40 {:ok, _bookmark2} = Bookmark.create(user2.id, activity.id)
41 {:ok, bookmark3} = Bookmark.create(user3.id, activity.id)
44 Ecto.Query.from(Pleroma.Activity)
45 |> Activity.with_preloaded_bookmark(user3)
48 assert queried_activity.bookmark == bookmark3
51 test "setting thread_muted?" do
52 activity = insert(:note_activity)
54 annoyed_user = insert(:user)
55 {:ok, _} = ThreadMute.add_mute(annoyed_user.id, activity.data["context"])
57 activity_with_unset_thread_muted_field =
58 Ecto.Query.from(Activity)
62 Ecto.Query.from(Activity)
63 |> Activity.with_set_thread_muted_field(user)
66 activity_for_annoyed_user =
67 Ecto.Query.from(Activity)
68 |> Activity.with_set_thread_muted_field(annoyed_user)
71 assert activity_with_unset_thread_muted_field.thread_muted? == nil
72 assert activity_for_user.thread_muted? == false
73 assert activity_for_annoyed_user.thread_muted? == true
76 describe "getting a bookmark" do
77 test "when association is loaded" do
79 activity = insert(:note_activity)
80 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
83 Ecto.Query.from(Pleroma.Activity)
84 |> Activity.with_preloaded_bookmark(user)
87 assert Activity.get_bookmark(queried_activity, user) == bookmark
90 test "when association is not loaded" do
92 activity = insert(:note_activity)
93 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
96 Ecto.Query.from(Pleroma.Activity)
99 assert Activity.get_bookmark(queried_activity, user) == bookmark