ability to set and reset avatar, profile banner and backgroud in Mastodon API
[akkoma] / test / activity_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.ActivityTest do
6 use Pleroma.DataCase
7 alias Pleroma.Activity
8 alias Pleroma.Bookmark
9 alias Pleroma.ThreadMute
10 import Pleroma.Factory
11
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"])
15
16 assert activity == found_activity
17 end
18
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"])
22
23 assert activity == found_activity
24 end
25
26 test "returns the activity that created an object" do
27 activity = insert(:note_activity)
28
29 found_activity = Activity.get_create_by_object_ap_id(activity.data["object"]["id"])
30
31 assert activity == found_activity
32 end
33
34 test "preloading a bookmark" do
35 user = insert(:user)
36 user2 = insert(:user)
37 user3 = insert(:user)
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)
42
43 queried_activity =
44 Ecto.Query.from(Pleroma.Activity)
45 |> Activity.with_preloaded_bookmark(user3)
46 |> Repo.one()
47
48 assert queried_activity.bookmark == bookmark3
49 end
50
51 test "setting thread_muted?" do
52 activity = insert(:note_activity)
53 user = insert(:user)
54 annoyed_user = insert(:user)
55 {:ok, _} = ThreadMute.add_mute(annoyed_user.id, activity.data["context"])
56
57 activity_with_unset_thread_muted_field =
58 Ecto.Query.from(Activity)
59 |> Repo.one()
60
61 activity_for_user =
62 Ecto.Query.from(Activity)
63 |> Activity.with_set_thread_muted_field(user)
64 |> Repo.one()
65
66 activity_for_annoyed_user =
67 Ecto.Query.from(Activity)
68 |> Activity.with_set_thread_muted_field(annoyed_user)
69 |> Repo.one()
70
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
74 end
75
76 describe "getting a bookmark" do
77 test "when association is loaded" do
78 user = insert(:user)
79 activity = insert(:note_activity)
80 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
81
82 queried_activity =
83 Ecto.Query.from(Pleroma.Activity)
84 |> Activity.with_preloaded_bookmark(user)
85 |> Repo.one()
86
87 assert Activity.get_bookmark(queried_activity, user) == bookmark
88 end
89
90 test "when association is not loaded" do
91 user = insert(:user)
92 activity = insert(:note_activity)
93 {:ok, bookmark} = Bookmark.create(user.id, activity.id)
94
95 queried_activity =
96 Ecto.Query.from(Pleroma.Activity)
97 |> Repo.one()
98
99 assert Activity.get_bookmark(queried_activity, user) == bookmark
100 end
101 end
102 end