Merge branch 'bugfix/repeating-announce' into 'develop'
[akkoma] / test / web / activity_pub / side_effects_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Notification
9 alias Pleroma.Object
10 alias Pleroma.Repo
11 alias Pleroma.Web.ActivityPub.ActivityPub
12 alias Pleroma.Web.ActivityPub.Builder
13 alias Pleroma.Web.ActivityPub.SideEffects
14 alias Pleroma.Web.CommonAPI
15
16 import Pleroma.Factory
17
18 describe "like objects" do
19 setup do
20 poster = insert(:user)
21 user = insert(:user)
22 {:ok, post} = CommonAPI.post(poster, %{"status" => "hey"})
23
24 {:ok, like_data, _meta} = Builder.like(user, post.object)
25 {:ok, like, _meta} = ActivityPub.persist(like_data, local: true)
26
27 %{like: like, user: user, poster: poster}
28 end
29
30 test "add the like to the original object", %{like: like, user: user} do
31 {:ok, like, _} = SideEffects.handle(like)
32 object = Object.get_by_ap_id(like.data["object"])
33 assert object.data["like_count"] == 1
34 assert user.ap_id in object.data["likes"]
35 end
36
37 test "creates a notification", %{like: like, poster: poster} do
38 {:ok, like, _} = SideEffects.handle(like)
39 assert Repo.get_by(Notification, user_id: poster.id, activity_id: like.id)
40 end
41 end
42 end