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