From 67389b77af7c6f9ccd18ec385b6ef4fd102e3eb6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 22 Jul 2020 13:10:10 -0500 Subject: [PATCH] Add AutolinkerToLinkify migration test --- .../20200716195806_autolinker_to_linkify.exs | 4 +- ...00716195806_autolinker_to_linkify_test.exs | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 test/migrations/20200716195806_autolinker_to_linkify_test.exs diff --git a/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs b/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs index 782a3cc55..570acba84 100644 --- a/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs +++ b/priv/repo/migrations/20200716195806_autolinker_to_linkify.exs @@ -1,7 +1,5 @@ defmodule Pleroma.Repo.Migrations.AutolinkerToLinkify do use Ecto.Migration - - alias Pleroma.Repo alias Pleroma.ConfigDB @autolinker_path %{group: :auto_linker, key: :opts} @@ -29,7 +27,7 @@ defp maybe_get_params() do end end - defp transform_opts(opts) when is_list(opts) do + def transform_opts(opts) when is_list(opts) do opts |> Enum.into(%{}) |> Map.take(@compat_opts) diff --git a/test/migrations/20200716195806_autolinker_to_linkify_test.exs b/test/migrations/20200716195806_autolinker_to_linkify_test.exs new file mode 100644 index 000000000..362cf5535 --- /dev/null +++ b/test/migrations/20200716195806_autolinker_to_linkify_test.exs @@ -0,0 +1,68 @@ +defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do + use Pleroma.DataCase + import Pleroma.Factory + alias Pleroma.ConfigDB + + setup_all do + [{module, _}] = + Code.require_file("20200716195806_autolinker_to_linkify.exs", "priv/repo/migrations") + + {:ok, %{migration: module}} + end + + test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: migration} do + autolinker_opts = [ + extra: true, + validate_tld: true, + class: false, + strip_prefix: false, + new_window: false, + rel: "ugc" + ] + + insert(:config, group: :auto_linker, key: :opts, value: autolinker_opts) + + migration.change() + + assert nil == ConfigDB.get_by_params(%{group: :auto_linker, key: :opts}) + + %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter}) + + assert new_opts == [ + class: false, + extra: true, + new_window: false, + rel: "ugc", + strip_prefix: false + ] + + {text, _mentions, []} = + Pleroma.Formatter.linkify( + "https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???" + ) + + assert text == + "https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???" + end + + test "transform_opts/1 returns a list of compatible opts", %{migration: migration} do + old_opts = [ + extra: true, + validate_tld: true, + class: false, + strip_prefix: false, + new_window: false, + rel: "ugc" + ] + + expected_opts = [ + class: false, + extra: true, + new_window: false, + rel: "ugc", + strip_prefix: false + ] + + assert migration.transform_opts(old_opts) == expected_opts + end +end