Add AutolinkerToLinkify migration test
[akkoma] / test / migrations / 20200716195806_autolinker_to_linkify_test.exs
1 defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
2 use Pleroma.DataCase
3 import Pleroma.Factory
4 alias Pleroma.ConfigDB
5
6 setup_all do
7 [{module, _}] =
8 Code.require_file("20200716195806_autolinker_to_linkify.exs", "priv/repo/migrations")
9
10 {:ok, %{migration: module}}
11 end
12
13 test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: migration} do
14 autolinker_opts = [
15 extra: true,
16 validate_tld: true,
17 class: false,
18 strip_prefix: false,
19 new_window: false,
20 rel: "ugc"
21 ]
22
23 insert(:config, group: :auto_linker, key: :opts, value: autolinker_opts)
24
25 migration.change()
26
27 assert nil == ConfigDB.get_by_params(%{group: :auto_linker, key: :opts})
28
29 %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
30
31 assert new_opts == [
32 class: false,
33 extra: true,
34 new_window: false,
35 rel: "ugc",
36 strip_prefix: false
37 ]
38
39 {text, _mentions, []} =
40 Pleroma.Formatter.linkify(
41 "https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???"
42 )
43
44 assert text ==
45 "<a href=\"https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\" rel=\"ugc\">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???"
46 end
47
48 test "transform_opts/1 returns a list of compatible opts", %{migration: migration} do
49 old_opts = [
50 extra: true,
51 validate_tld: true,
52 class: false,
53 strip_prefix: false,
54 new_window: false,
55 rel: "ugc"
56 ]
57
58 expected_opts = [
59 class: false,
60 extra: true,
61 new_window: false,
62 rel: "ugc",
63 strip_prefix: false
64 ]
65
66 assert migration.transform_opts(old_opts) == expected_opts
67 end
68 end