Merge remote-tracking branch 'origin/develop' into global-status-expiration
[akkoma] / test / web / activity_pub / mrf / activity_expiration_policy_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.MRF.ActivityExpirationPolicyTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
8
9 @id Pleroma.Web.Endpoint.url() <> "/activities/cofe"
10
11 test "adds `expires_at` property" do
12 assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
13 ActivityExpirationPolicy.filter(%{"id" => @id, "type" => "Create"})
14
15 assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
16 end
17
18 test "keeps existing `expires_at` if it less than the config setting" do
19 expires_at = NaiveDateTime.utc_now() |> Timex.shift(days: 1)
20
21 assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
22 ActivityExpirationPolicy.filter(%{
23 "id" => @id,
24 "type" => "Create",
25 "expires_at" => expires_at
26 })
27 end
28
29 test "overwrites existing `expires_at` if it greater than the config setting" do
30 too_distant_future = NaiveDateTime.utc_now() |> Timex.shift(years: 2)
31
32 assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
33 ActivityExpirationPolicy.filter(%{
34 "id" => @id,
35 "type" => "Create",
36 "expires_at" => too_distant_future
37 })
38
39 assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
40 end
41
42 test "ignores remote activities" do
43 assert {:ok, activity} =
44 ActivityExpirationPolicy.filter(%{
45 "id" => "https://example.com/123",
46 "type" => "Create"
47 })
48
49 refute Map.has_key?(activity, "expires_at")
50 end
51
52 test "ignores non-Create activities" do
53 assert {:ok, activity} =
54 ActivityExpirationPolicy.filter(%{
55 "id" => "https://example.com/123",
56 "type" => "Follow"
57 })
58
59 refute Map.has_key?(activity, "expires_at")
60 end
61 end