merge develop
[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 do
9 Tesla.Mock.mock(fn
10 %{
11 method: :get,
12 url: "http://example.com/rel_me/anchor"
13 } ->
14 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}
15
16 %{
17 method: :get,
18 url: "http://example.com/rel_me/anchor_nofollow"
19 } ->
20 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}
21
22 %{
23 method: :get,
24 url: "http://example.com/rel_me/link"
25 } ->
26 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}
27
28 %{
29 method: :get,
30 url: "http://example.com/rel_me/null"
31 } ->
32 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}
33 end)
34
35 :ok
36 end
37
38 test "parse/1" do
39 hrefs = ["https://social.example.org/users/lain"]
40
41 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
42 assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
43
44 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
45 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
46 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor_nofollow") == {:ok, hrefs}
47 end
48
49 test "maybe_put_rel_me/2" do
50 profile_urls = ["https://social.example.org/users/lain"]
51 attr = "me"
52 fallback = nil
53
54 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
55 fallback
56
57 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
58 fallback
59
60 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
61 attr
62
63 assert Pleroma.Web.RelMe.maybe_put_rel_me(
64 "http://example.com/rel_me/anchor_nofollow",
65 profile_urls
66 ) == attr
67
68 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
69 attr
70 end
71 end