1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
8 alias Pleroma.Notification
11 alias Pleroma.Web.ActivityPub.ActivityPub
12 alias Pleroma.Web.ActivityPub.Builder
13 alias Pleroma.Web.ActivityPub.SideEffects
14 alias Pleroma.Web.CommonAPI
16 import Pleroma.Factory
18 describe "like objects" do
20 poster = insert(:user)
22 {:ok, post} = CommonAPI.post(poster, %{"status" => "hey"})
24 {:ok, like_data, _meta} = Builder.like(user, post.object)
25 {:ok, like, _meta} = ActivityPub.persist(like_data, local: true)
27 %{like: like, user: user, poster: poster}
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"]
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)