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"
11 test "adds `expires_at` property" do
12 assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
13 ActivityExpirationPolicy.filter(%{
16 "object" => %{"type" => "Note"}
19 assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
22 test "keeps existing `expires_at` if it less than the config setting" do
23 expires_at = NaiveDateTime.utc_now() |> Timex.shift(days: 1)
25 assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
26 ActivityExpirationPolicy.filter(%{
29 "expires_at" => expires_at,
30 "object" => %{"type" => "Note"}
34 test "overwrites existing `expires_at` if it greater than the config setting" do
35 too_distant_future = NaiveDateTime.utc_now() |> Timex.shift(years: 2)
37 assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
38 ActivityExpirationPolicy.filter(%{
41 "expires_at" => too_distant_future,
42 "object" => %{"type" => "Note"}
45 assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
48 test "ignores remote activities" do
49 assert {:ok, activity} =
50 ActivityExpirationPolicy.filter(%{
51 "id" => "https://example.com/123",
53 "object" => %{"type" => "Note"}
56 refute Map.has_key?(activity, "expires_at")
59 test "ignores non-Create/Note activities" do
60 assert {:ok, activity} =
61 ActivityExpirationPolicy.filter(%{
62 "id" => "https://example.com/123",
66 refute Map.has_key?(activity, "expires_at")
68 assert {:ok, activity} =
69 ActivityExpirationPolicy.filter(%{
70 "id" => "https://example.com/123",
72 "object" => %{"type" => "Cofe"}
75 refute Map.has_key?(activity, "expires_at")