Merge branch 'fix/backup-url-on-s3' into 'develop'
[akkoma] / test / pleroma / web / media_proxy / invalidation / http_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.MediaProxy.Invalidation.HttpTest do
6 use ExUnit.Case
7 alias Pleroma.Web.MediaProxy.Invalidation
8
9 import ExUnit.CaptureLog
10 import Tesla.Mock
11
12 test "logs hasn't error message when request is valid" do
13 mock(fn
14 %{method: :purge, url: "http://example.com/media/example.jpg"} ->
15 %Tesla.Env{status: 200}
16 end)
17
18 refute capture_log(fn ->
19 assert Invalidation.Http.purge(
20 ["http://example.com/media/example.jpg"],
21 []
22 ) == {:ok, ["http://example.com/media/example.jpg"]}
23 end) =~ "Error while cache purge"
24 end
25
26 test "it write error message in logs when request invalid" do
27 mock(fn
28 %{method: :purge, url: "http://example.com/media/example1.jpg"} ->
29 %Tesla.Env{status: 404}
30 end)
31
32 assert capture_log(fn ->
33 assert Invalidation.Http.purge(
34 ["http://example.com/media/example1.jpg"],
35 []
36 ) == {:ok, ["http://example.com/media/example1.jpg"]}
37 end) =~ "Error while cache purge: url - http://example.com/media/example1.jpg"
38 end
39 end