summaryrefslogtreecommitdiff
path: root/test/web/rich_media/helpers_test.exs
blob: 60d93768f20f5b1fd5cd968b12a279d64d770e34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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