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 describe "preloading bookmarks" do
38 activity = insert(:note_activity)
39 {:ok, bookmark1} = Bookmark.create(user1.id, activity.id)
40 {:ok, bookmark2} = Bookmark.create(user2.id, activity.id)
41 [activity: activity, bookmarks: Enum.sort([bookmark1, bookmark2])]
44 test "using with_preloaded_bookmarks", %{activity: activity, bookmarks: bookmarks} do
46 Ecto.Query.from(a in Activity, where: a.id == ^activity.id)
47 |> Activity.with_preloaded_bookmarks()
50 assert Enum.sort(queried_activity.bookmarks) == bookmarks
53 test "using with_preloaded_object", %{activity: activity, bookmarks: bookmarks} do
55 Ecto.Query.from(a in Activity, where: a.id == ^activity.id)
56 |> Activity.with_preloaded_object()
59 assert Enum.sort(queried_activity.bookmarks) == bookmarks
62 test "using get_by_ap_id_with_object", %{activity: activity, bookmarks: bookmarks} do
63 queried_activity = Activity.get_by_ap_id_with_object(activity.data["id"])
64 assert Enum.sort(queried_activity.bookmarks) == bookmarks
67 test "using get_by_id_with_object", %{activity: activity, bookmarks: bookmarks} do
68 queried_activity = Activity.get_by_id_with_object(activity.id)
69 assert Enum.sort(queried_activity.bookmarks) == bookmarks
72 test "using get_create_by_object_ap_id_with_object", %{
77 Activity.get_create_by_object_ap_id_with_object(Object.normalize(activity).data["id"])
79 assert Enum.sort(queried_activity.bookmarks) == bookmarks