Web.RelMe: Fix having other values in rel attr
[akkoma] / test / web / rel_me_test.exs
1 defmodule Pleroma.Web.RelMeTest do
2 use ExUnit.Case, async: true
3
4 setup do
5 Tesla.Mock.mock(fn
6 %{
7 method: :get,
8 url: "http://example.com/rel_me/anchor"
9 } ->
10 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}
11
12 %{
13 method: :get,
14 url: "http://example.com/rel_me/anchor_nofollow"
15 } ->
16 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}
17
18 %{
19 method: :get,
20 url: "http://example.com/rel_me/link"
21 } ->
22 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}
23
24 %{
25 method: :get,
26 url: "http://example.com/rel_me/null"
27 } ->
28 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}
29 end)
30
31 :ok
32 end
33
34 test "parse/1" do
35 hrefs = ["https://social.example.org/users/lain"]
36
37 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
38 assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
39
40 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
41 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 end
44
45 test "maybe_put_rel_me/2" do
46 profile_urls = ["https://social.example.org/users/lain"]
47 attr = "me"
48 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 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
57 attr
58
59 assert Pleroma.Web.RelMe.maybe_put_rel_me(
60 "http://example.com/rel_me/anchor_nofollow",
61 profile_urls
62 ) == attr
63
64 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
65 attr
66 end
67 end