logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

20200722185515_fix_malformed_formatter_config_test.exs (2200B)


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