1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
7 use Pleroma.Tests.Helpers
10 alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
18 "content" => "content",
20 %{"url" => [%{"href" => "http://example.com/image.jpg"}]}
25 setup do: clear_config([:media_proxy, :enabled], true)
27 test "it prefetches media proxy URIs" do
28 Tesla.Mock.mock(fn %{method: :get, url: "http://example.com/image.jpg"} ->
29 {:ok, %Tesla.Env{status: 200, body: ""}}
32 with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
33 MediaProxyWarmingPolicy.filter(@message)
35 assert called(HTTP.get(:_, :_, :_))
39 test "it does nothing when no attachments are present" do
42 |> Map.delete("attachment")
46 |> Map.put("object", object)
48 with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
49 MediaProxyWarmingPolicy.filter(message)
50 refute called(HTTP.get(:_, :_, :_))