RichMediaTest: Use mocked config
This commit is contained in:
parent
650edb60dc
commit
00def0875b
3 changed files with 41 additions and 12 deletions
|
|
@ -5,20 +5,29 @@
|
|||
defmodule Pleroma.Web.RichMedia.HelpersTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.RichMedia.Helpers
|
||||
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> false
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|> stub(:get, fn
|
||||
path, default -> Pleroma.Test.StaticConfig.get(path, default)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:rich_media, :enabled])
|
||||
|
||||
test "refuses to crawl incomplete URLs" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -28,7 +37,11 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
end
|
||||
|
|
@ -42,7 +55,11 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
end
|
||||
|
|
@ -56,12 +73,18 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
content_type: "text/markdown"
|
||||
})
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
assert %{page_url: "https://example.com/ogp", rich_media: _} =
|
||||
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||
end
|
||||
|
||||
# This does not seem to work. The urls are being fetched.
|
||||
@tag skip: true
|
||||
test "refuses to crawl URLs of private network from posts" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -73,7 +96,11 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
{:ok, activity4} = CommonAPI.post(user, %{status: "https://192.168.10.40/notice/9kCP7V"})
|
||||
{:ok, activity5} = CommonAPI.post(user, %{status: "https://pleroma.local/notice/9kCP7V"})
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
ConfigMock
|
||||
|> stub(:get, fn
|
||||
[:rich_media, :enabled] -> true
|
||||
path -> Pleroma.Test.StaticConfig.get(path)
|
||||
end)
|
||||
|
||||
assert %{} = Helpers.fetch_data_for_activity(activity)
|
||||
assert %{} = Helpers.fetch_data_for_activity(activity2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue