summaryrefslogtreecommitdiff
path: root/test/web/activity_pub/mrf/activity_expiration_policy_test.exs
blob: 2f2f90b44a2e119b82f22b89f4645d8d5566ab86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
  use ExUnit.Case, async: true
  alias Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy

  @id Pleroma.Web.Endpoint.url() <> "/activities/cofe"

  test "adds `expires_at` property" do
    assert {:ok, %{"expires_at" => expires_at}} = ActivityExpirationPolicy.filter(%{"id" => @id})

    assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
  end

  test "keeps existing `expires_at` if it less than the config setting" do
    expires_at = NaiveDateTime.utc_now() |> Timex.shift(days: 1)

    assert {:ok, %{"expires_at" => ^expires_at}} =
             ActivityExpirationPolicy.filter(%{"id" => @id, "expires_at" => expires_at})
  end

  test "overwrites existing `expires_at` if it greater than the config setting" do
    too_distant_future = NaiveDateTime.utc_now() |> Timex.shift(years: 2)

    assert {:ok, %{"expires_at" => expires_at}} =
             ActivityExpirationPolicy.filter(%{"id" => @id, "expires_at" => too_distant_future})

    assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
  end

  test "ignores remote activities" do
    assert {:ok, activity} = ActivityExpirationPolicy.filter(%{"id" => "https://example.com/123"})

    refute Map.has_key?(activity, "expires_at")
  end
end