Merge branch 'feature/mrf-mediaproxy-warm' into 'develop'
[akkoma] / test / web / activity_pub / mrf / mediaproxy_warming_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
10
11 import Mock
12
13 @message %{
14 "type" => "Create",
15 "object" => %{
16 "type" => "Note",
17 "content" => "content",
18 "attachment" => [
19 %{"url" => [%{"href" => "http://example.com/image.jpg"}]}
20 ]
21 }
22 }
23
24 test "it prefetches media proxy URIs" do
25 with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
26 MediaProxyWarmingPolicy.filter(@message)
27 assert called(HTTP.get(:_, :_, :_))
28 end
29 end
30
31 test "it does nothing when no attachments are present" do
32 object =
33 @message["object"]
34 |> Map.delete("attachment")
35
36 message =
37 @message
38 |> Map.put("object", object)
39
40 with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
41 MediaProxyWarmingPolicy.filter(message)
42 refute called(HTTP.get(:_, :_, :_))
43 end
44 end
45 end