logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

fix_malformed_formatter_config_test.exs (2364B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfigTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. import Pleroma.Tests.Helpers
  8. alias Pleroma.ConfigDB
  9. setup do: clear_config(Pleroma.Formatter)
  10. setup_all do: require_migration("20200722185515_fix_malformed_formatter_config")
  11. test "change/0 converts a map into a list", %{migration: migration} do
  12. incorrect_opts = %{
  13. class: false,
  14. extra: true,
  15. new_window: false,
  16. rel: "F",
  17. strip_prefix: false
  18. }
  19. insert(:config, group: :pleroma, key: Pleroma.Formatter, value: incorrect_opts)
  20. assert :ok == migration.change()
  21. %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
  22. assert Keyword.equal?(new_opts,
  23. class: false,
  24. extra: true,
  25. new_window: false,
  26. rel: "F",
  27. strip_prefix: false
  28. )
  29. clear_config(Pleroma.Formatter, new_opts)
  30. assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
  31. {text, _mentions, []} =
  32. Pleroma.Formatter.linkify(
  33. "https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???"
  34. )
  35. assert text ==
  36. "<a href=\"https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\" rel=\"F\">https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7</a>\n\nOmg will COVID finally end Black Friday???"
  37. end
  38. test "change/0 skips if Pleroma.Formatter config is already a list", %{migration: migration} do
  39. opts = [
  40. class: false,
  41. extra: true,
  42. new_window: false,
  43. rel: "ugc",
  44. strip_prefix: false
  45. ]
  46. insert(:config, group: :pleroma, key: Pleroma.Formatter, value: opts)
  47. assert :skipped == migration.change()
  48. %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
  49. assert new_opts == opts
  50. end
  51. test "change/0 skips if Pleroma.Formatter is empty", %{migration: migration} do
  52. assert :skipped == migration.change()
  53. end
  54. end