Merge branch 'bugfix/delete-activity-audience' of git.pleroma.social:pleroma/pleroma...
[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/link"
15 } ->
16 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}
17
18 %{
19 method: :get,
20 url: "http://example.com/rel_me/null"
21 } ->
22 %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}
23 end)
24
25 :ok
26 end
27
28 test "parse/1" do
29 hrefs = ["https://social.example.org/users/lain"]
30
31 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
32 assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
33
34 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
35 assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
36 end
37
38 test "maybe_put_rel_me/2" do
39 profile_urls = ["https://social.example.org/users/lain"]
40 attr = "me"
41 fallback = nil
42
43 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
44 fallback
45
46 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
47 fallback
48
49 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
50 attr
51
52 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
53 attr
54 end
55 end