fix test
[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(:banned_urls_cache) end)
10 end
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