Merge remote-tracking branch 'pleroma/develop' into cycles-constants
[akkoma] / test / pleroma / web / rel_me_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.RelMeTest do
6 use Pleroma.DataCase
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
18 assert {:ok, %Tesla.Env{status: 404}} =
19 Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
20
21 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
22 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
23 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor_nofollow") == {:ok, hrefs}
24 end
25
26 test "maybe_put_rel_me/2" do
27 profile_urls = ["https://social.example.org/users/lain"]
28 attr = "me"
29 fallback = nil
30
31 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
32 fallback
33
34 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
35 fallback
36
37 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
38 attr
39
40 assert Pleroma.Web.RelMe.maybe_put_rel_me(
41 "http://example.com/rel_me/anchor_nofollow",
42 profile_urls
43 ) == attr
44
45 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
46 attr
47 end
48 end