Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2KB

  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. defmodule Pleroma.Web.RelMeTest do
  5. use ExUnit.Case, async: true
  6. setup do
  7. Tesla.Mock.mock(fn
  8. %{
  9. method: :get,
  10. url: "http://example.com/rel_me/anchor"
  11. } ->
  12. %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}
  13. %{
  14. method: :get,
  15. url: "http://example.com/rel_me/anchor_nofollow"
  16. } ->
  17. %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}
  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. method: :get,
  25. url: "http://example.com/rel_me/null"
  26. } ->
  27. %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}
  28. end)
  29. :ok
  30. end
  31. test "parse/1" do
  32. hrefs = ["https://social.example.org/users/lain"]
  33. assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
  34. assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
  35. assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
  36. assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
  37. assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor_nofollow") == {:ok, hrefs}
  38. end
  39. test "maybe_put_rel_me/2" do
  40. profile_urls = ["https://social.example.org/users/lain"]
  41. attr = "me"
  42. fallback = nil
  43. assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
  44. fallback
  45. assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/error", profile_urls) ==
  46. fallback
  47. assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
  48. attr
  49. assert Pleroma.Web.RelMe.maybe_put_rel_me(
  50. "http://example.com/rel_me/anchor_nofollow",
  51. profile_urls
  52. ) == attr
  53. assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
  54. attr
  55. end
  56. end