Refactor User.post_register_action/1 emails
[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 import Pleroma.Tests.Helpers
5 alias Pleroma.ConfigDB
6
7 setup do: clear_config(Pleroma.Formatter)
8 setup_all do: require_migration("20200716195806_autolinker_to_linkify")
9
10 test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: migration} do
11 autolinker_opts = [
12 extra: true,
13 validate_tld: true,
14 class: false,
15 strip_prefix: false,
16 new_window: false,
17 rel: "testing"
18 ]
19
20 insert(:config, group: :auto_linker, key: :opts, value: autolinker_opts)
21
22 migration.change()
23
24 assert nil == ConfigDB.get_by_params(%{group: :auto_linker, key: :opts})
25
26 %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
27
28 assert new_opts == [
29 class: false,
30 extra: true,
31 new_window: false,
32 rel: "testing",
33 strip_prefix: false
34 ]
35
36 Pleroma.Config.put(Pleroma.Formatter, new_opts)
37 assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
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=\"testing\">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: "qqq"
56 ]
57
58 expected_opts = [
59 class: false,
60 extra: true,
61 new_window: false,
62 rel: "qqq",
63 strip_prefix: false
64 ]
65
66 assert migration.transform_opts(old_opts) == expected_opts
67 end
68 end