Pleroma.Web.RelMeTest: Add test against Pleroma.Web.RelMe
[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 = "rel=\"me\" "
41
42 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
43 ""
44
45 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
46 ""
47
48 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
49 attr
50
51 assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
52 attr
53 end
54 end