From d7a278a733616d01ee41c3923a3d87730c685879 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 24 Feb 2019 19:39:27 +0000 Subject: [PATCH] tests: add tests for rich media helper functions --- test/web/rich_media/helpers_test.exs | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/web/rich_media/helpers_test.exs diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs new file mode 100644 index 000000000..9285f078d --- /dev/null +++ b/test/web/rich_media/helpers_test.exs @@ -0,0 +1,42 @@ +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" + }) + + assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity) + 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