Merge remote-tracking branch 'remotes/origin/develop' into ostatus-controller-no...
[akkoma] / test / pleroma / web / activity_pub / mrf / media_proxy_warming_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.MediaProxyWarmingPolicyTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.HTTP
9 alias Pleroma.Tests.ObanHelpers
10 alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
11
12 import Mock
13
14 @message %{
15 "type" => "Create",
16 "object" => %{
17 "type" => "Note",
18 "content" => "content",
19 "attachment" => [
20 %{"url" => [%{"href" => "http://example.com/image.jpg"}]}
21 ]
22 }
23 }
24
25 setup do: clear_config([:media_proxy, :enabled], true)
26
27 test "it prefetches media proxy URIs" do
28 with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
29 MediaProxyWarmingPolicy.filter(@message)
30
31 ObanHelpers.perform_all()
32 # Performing jobs which has been just enqueued
33 ObanHelpers.perform_all()
34
35 assert called(HTTP.get(:_, :_, :_))
36 end
37 end
38
39 test "it does nothing when no attachments are present" do
40 object =
41 @message["object"]
42 |> Map.delete("attachment")
43
44 message =
45 @message
46 |> Map.put("object", object)
47
48 with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
49 MediaProxyWarmingPolicy.filter(message)
50 refute called(HTTP.get(:_, :_, :_))
51 end
52 end
53 end