Merge pull request 'Remove "default" image description' (#493) from ilja/akkoma:remov...
[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
30 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
31 {:error, {:could_not_verify, "http://example.com/rel_me/null", {:link_match, false}}}
32
33 assert {:error, {:could_not_fetch, "http://example.com/rel_me/error", _}} =
34 Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls)
35
36 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
37 attr
38
39 assert Pleroma.Web.RelMe.maybe_put_rel_me(
40 "http://example.com/rel_me/anchor_nofollow",
41 profile_urls
42 ) == attr
43
44 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
45 attr
46 end
47 end