rel_me_test.exs 2.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
defmodule Pleroma.Web.RelMeTest do
  use ExUnit.Case, async: true

  setup do
    Tesla.Mock.mock(fn
      %{
        method: :get,
        url: "http://example.com/rel_me/anchor"
      } ->
        %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}

12
13
14
15
16
17
      %{
        method: :get,
        url: "http://example.com/rel_me/anchor_nofollow"
      } ->
        %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
      %{
        method: :get,
        url: "http://example.com/rel_me/link"
      } ->
        %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}

      %{
        method: :get,
        url: "http://example.com/rel_me/null"
      } ->
        %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}
    end)

    :ok
  end

  test "parse/1" do
    hrefs = ["https://social.example.org/users/lain"]

    assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
    assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")

    assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
    assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
42
    assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor_nofollow") == {:ok, hrefs}
43
44
45
46
  end

  test "maybe_put_rel_me/2" do
    profile_urls = ["https://social.example.org/users/lain"]
47
48
    attr = "me"
    fallback = nil
49
50

    assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
51
             fallback
52
53

    assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
54
             fallback
55
56
57
58

    assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
             attr

59
60
61
62
63
    assert Pleroma.Web.RelMe.maybe_put_rel_me(
             "http://example.com/rel_me/anchor_nofollow",
             profile_urls
           ) == attr

64
65
66
67
    assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
             attr
  end
end