Merge branch 'develop' into feature/reports-groups-and-multiple-state-update
[akkoma] / test / web / rel_me_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.RelMeTest do
6 use ExUnit.Case, async: true
7
8 setup_all do
9 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
10 :ok
11 end
12
13 test "parse/1" do
14 hrefs = ["https://social.example.org/users/lain"]
15
16 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
17 assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
18
19 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
20 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
21 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor_nofollow") == {:ok, hrefs}
22 end
23
24 test "maybe_put_rel_me/2" do
25 profile_urls = ["https://social.example.org/users/lain"]
26 attr = "me"
27 fallback = nil
28
29 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
30 fallback
31
32 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
33 fallback
34
35 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
36 attr
37
38 assert Pleroma.Web.RelMe.maybe_put_rel_me(
39 "http://example.com/rel_me/anchor_nofollow",
40 profile_urls
41 ) == attr
42
43 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
44 attr
45 end
46 end