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
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 object preloads bookmarks" do
37 activity = insert(:note_activity)
38 {:ok, bookmark1} = Bookmark.create(user1.id, activity.id)
39 {:ok, bookmark2} = Bookmark.create(user2.id, activity.id)
40 bookmarks = Enum.sort([bookmark1, bookmark2])
43 Ecto.Query.from(a in Activity, where: a.id == ^activity.id)
44 |> Activity.with_preloaded_object()
47 assert Enum.sort(queried_activity.bookmarks) == bookmarks
49 queried_activity = Activity.get_by_ap_id_with_object(activity.data["id"])
50 assert Enum.sort(queried_activity.bookmarks) == bookmarks
52 queried_activity = Activity.get_by_id_with_object(activity.id)
53 assert Enum.sort(queried_activity.bookmarks) == bookmarks
56 Activity.get_create_by_object_ap_id_with_object(Object.normalize(activity).data["id"])
58 assert Enum.sort(queried_activity.bookmarks) == bookmarks