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.MRF.ActivityExpirationPolicyTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
9 @id Pleroma.Web.Endpoint.url() <> "/activities/cofe"
10 @local_actor Pleroma.Web.Endpoint.url() <> "/users/cofe"
12 test "adds `expires_at` property" do
13 assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
14 ActivityExpirationPolicy.filter(%{
16 "actor" => @local_actor,
18 "object" => %{"type" => "Note"}
21 assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
24 test "keeps existing `expires_at` if it less than the config setting" do
25 expires_at = DateTime.utc_now() |> Timex.shift(days: 1)
27 assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
28 ActivityExpirationPolicy.filter(%{
30 "actor" => @local_actor,
32 "expires_at" => expires_at,
33 "object" => %{"type" => "Note"}
37 test "overwrites existing `expires_at` if it greater than the config setting" do
38 too_distant_future = DateTime.utc_now() |> Timex.shift(years: 2)
40 assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
41 ActivityExpirationPolicy.filter(%{
43 "actor" => @local_actor,
45 "expires_at" => too_distant_future,
46 "object" => %{"type" => "Note"}
49 assert Timex.diff(expires_at, DateTime.utc_now(), :days) == 364
52 test "ignores remote activities" do
53 assert {:ok, activity} =
54 ActivityExpirationPolicy.filter(%{
55 "id" => "https://example.com/123",
56 "actor" => "https://example.com/users/cofe",
58 "object" => %{"type" => "Note"}
61 refute Map.has_key?(activity, "expires_at")
64 test "ignores non-Create/Note activities" do
65 assert {:ok, activity} =
66 ActivityExpirationPolicy.filter(%{
67 "id" => "https://example.com/123",
68 "actor" => "https://example.com/users/cofe",
72 refute Map.has_key?(activity, "expires_at")
74 assert {:ok, activity} =
75 ActivityExpirationPolicy.filter(%{
76 "id" => "https://example.com/123",
77 "actor" => "https://example.com/users/cofe",
79 "object" => %{"type" => "Cofe"}
82 refute Map.has_key?(activity, "expires_at")