diff options
| author | link0ff <juri@linkov.net> | 2019-03-14 17:43:30 +0200 |
|---|---|---|
| committer | link0ff <juri@linkov.net> | 2019-03-14 17:43:30 +0200 |
| commit | 54e7087ab412a488f8ad7286aef89d313e5e7b14 (patch) | |
| tree | 9391107eb5aec3940bf6150539acc38e85224751 /test/web/rich_media/helpers_test.exs | |
| parent | 9338f061a303ae3d57a8ea1af524c2ca51929f8d (diff) | |
| parent | 59333f2d568dc6e50fb72e5114ec7dd6bcc1ebef (diff) | |
| download | pleroma-54e7087ab412a488f8ad7286aef89d313e5e7b14.tar.gz pleroma-54e7087ab412a488f8ad7286aef89d313e5e7b14.zip | |
Merge remote-tracking branch 'upstream/develop' into feature/openldap-support
Diffstat (limited to 'test/web/rich_media/helpers_test.exs')
| -rw-r--r-- | test/web/rich_media/helpers_test.exs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs new file mode 100644 index 000000000..60d93768f --- /dev/null +++ b/test/web/rich_media/helpers_test.exs @@ -0,0 +1,62 @@ +defmodule Pleroma.Web.RichMedia.HelpersTest do + use Pleroma.DataCase + + alias Pleroma.Web.CommonAPI + + import Pleroma.Factory + import Tesla.Mock + + setup do + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end + + test "refuses to crawl incomplete URLs" do + user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => "[test](example.com/ogp)", + "content_type" => "text/markdown" + }) + + Pleroma.Config.put([:rich_media, :enabled], true) + + assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) + + Pleroma.Config.put([:rich_media, :enabled], false) + end + + test "refuses to crawl malformed URLs" do + user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => "[test](example.com[]/ogp)", + "content_type" => "text/markdown" + }) + + Pleroma.Config.put([:rich_media, :enabled], true) + + assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) + + Pleroma.Config.put([:rich_media, :enabled], false) + end + + test "crawls valid, complete URLs" do + user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => "[test](http://example.com/ogp)", + "content_type" => "text/markdown" + }) + + Pleroma.Config.put([:rich_media, :enabled], true) + + assert %{page_url: "http://example.com/ogp", rich_media: _} = + Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) + + Pleroma.Config.put([:rich_media, :enabled], false) + end +end |
