Apply suggestion to test/web/admin_api/controllers/media_proxy_cache_controller_test.exs
[akkoma] / test / web / media_proxy / invalidations / http_test.exs
1 defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
2 use ExUnit.Case
3 alias Pleroma.Web.MediaProxy.Invalidation
4
5 import ExUnit.CaptureLog
6 import Tesla.Mock
7
8 setup do
9 on_exit(fn -> Cachex.clear(:deleted_urls_cache) end)
10 :ok
11 end
12
13 test "logs hasn't error message when request is valid" do
14 mock(fn
15 %{method: :purge, url: "http://example.com/media/example.jpg"} ->
16 %Tesla.Env{status: 200}
17 end)
18
19 refute capture_log(fn ->
20 assert Invalidation.Http.purge(
21 ["http://example.com/media/example.jpg"],
22 []
23 ) == {:ok, ["http://example.com/media/example.jpg"]}
24 end) =~ "Error while cache purge"
25 end
26
27 test "it write error message in logs when request invalid" do
28 mock(fn
29 %{method: :purge, url: "http://example.com/media/example1.jpg"} ->
30 %Tesla.Env{status: 404}
31 end)
32
33 assert capture_log(fn ->
34 assert Invalidation.Http.purge(
35 ["http://example.com/media/example1.jpg"],
36 []
37 ) == {:ok, ["http://example.com/media/example1.jpg"]}
38 end) =~ "Error while cache purge: url - http://example.com/media/example1.jpg"
39 end
40 end