fix tests
[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 test "logs hasn't error message when request is valid" do
9 mock(fn
10 %{method: :purge, url: "http://example.com/media/example.jpg"} ->
11 %Tesla.Env{status: 200}
12 end)
13
14 refute capture_log(fn ->
15 assert Invalidation.Http.purge(
16 ["http://example.com/media/example.jpg"],
17 %{}
18 ) == {:ok, "success"}
19 end) =~ "Error while cache purge"
20 end
21
22 test "it write error message in logs when request invalid" do
23 mock(fn
24 %{method: :purge, url: "http://example.com/media/example1.jpg"} ->
25 %Tesla.Env{status: 404}
26 end)
27
28 assert capture_log(fn ->
29 assert Invalidation.Http.purge(
30 ["http://example.com/media/example1.jpg"],
31 %{}
32 ) == {:ok, "success"}
33 end) =~ "Error while cache purge: url - http://example.com/media/example1.jpg"
34 end
35 end