Merge branch 'refactor/remove-inReplyToStatusId' into 'develop'
[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 import Pleroma.Factory
9
10 test "returns an activity by it's AP id" do
11 activity = insert(:note_activity)
12 found_activity = Activity.get_by_ap_id(activity.data["id"])
13
14 assert activity == found_activity
15 end
16
17 test "returns activities by it's objects AP ids" do
18 activity = insert(:note_activity)
19 [found_activity] = Activity.get_all_create_by_object_ap_id(activity.data["object"]["id"])
20
21 assert activity == found_activity
22 end
23
24 test "returns the activity that created an object" do
25 activity = insert(:note_activity)
26
27 found_activity = Activity.get_create_by_object_ap_id(activity.data["object"]["id"])
28
29 assert activity == found_activity
30 end
31
32 test "reply count" do
33 %{id: id, data: %{"object" => %{"id" => object_ap_id}}} = activity = insert(:note_activity)
34
35 replies_count = activity.data["object"]["repliesCount"] || 0
36 expected_increase = replies_count + 1
37 Activity.increase_replies_count(object_ap_id)
38 %{data: %{"object" => %{"repliesCount" => actual_increase}}} = Activity.get_by_id(id)
39 assert expected_increase == actual_increase
40 expected_decrease = expected_increase - 1
41 Activity.decrease_replies_count(object_ap_id)
42 %{data: %{"object" => %{"repliesCount" => actual_decrease}}} = Activity.get_by_id(id)
43 assert expected_decrease == actual_decrease
44 end
45 end