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
11 test "returns an activity by it's AP id" do
12 activity = insert(:note_activity)
13 found_activity = Activity.get_by_ap_id(activity.data["id"])
15 assert activity == found_activity
18 test "returns activities by it's objects AP ids" do
19 activity = insert(:note_activity)
20 [found_activity] = Activity.get_all_create_by_object_ap_id(activity.data["object"]["id"])
22 assert activity == found_activity
25 test "returns the activity that created an object" do
26 activity = insert(:note_activity)
28 found_activity = Activity.get_create_by_object_ap_id(activity.data["object"]["id"])
30 assert activity == found_activity
33 test "preloading a bookmark" do
37 activity = insert(:note_activity)
38 {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
39 {:ok, _bookmark2} = Bookmark.create(user2.id, activity.id)
40 {:ok, bookmark3} = Bookmark.create(user3.id, activity.id)
43 Ecto.Query.from(Pleroma.Activity)
44 |> Activity.with_preloaded_bookmark(user3)
47 assert queried_activity.bookmark == bookmark3
50 describe "getting a bookmark" do
51 test "when association is loaded" do
53 activity = insert(:note_activity)
54 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
57 Ecto.Query.from(Pleroma.Activity)
58 |> Activity.with_preloaded_bookmark(user)
61 assert Activity.get_bookmark(queried_activity, user) == bookmark
64 test "when association is not loaded" do
66 activity = insert(:note_activity)
67 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
70 Ecto.Query.from(Pleroma.Activity)
73 assert Activity.get_bookmark(queried_activity, user) == bookmark