9e8f997a01ca556f07489718a4dbe8d8cb1c726a
[akkoma] / test / migrations / 20200722185515_fix_malformed_formatter_config_test.exs
1 defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfigTest 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("20200722185515_fix_malformed_formatter_config")
8
9 test "change/0 converts a map into a list", %{migration: migration} do
10 incorrect_opts = %{
11 class: false,
12 extra: true,
13 new_window: false,
14 rel: "ugc",
15 strip_prefix: false
16 }
17
18 insert(:config, group: :pleroma, key: Pleroma.Formatter, value: incorrect_opts)
19
20 assert :ok == migration.change()
21
22 %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
23
24 assert new_opts == [
25 class: false,
26 extra: true,
27 new_window: false,
28 rel: "ugc",
29 strip_prefix: false
30 ]
31
32 {text, _mentions, []} =
33 Pleroma.Formatter.linkify(
34 "https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???"
35 )
36
37 assert text ==
38 "<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???"
39 end
40
41 test "change/0 skips if Pleroma.Formatter config is already a list", %{migration: migration} do
42 opts = [
43 class: false,
44 extra: true,
45 new_window: false,
46 rel: "ugc",
47 strip_prefix: false
48 ]
49
50 insert(:config, group: :pleroma, key: Pleroma.Formatter, value: opts)
51
52 assert :skipped == migration.change()
53
54 %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
55
56 assert new_opts == opts
57 end
58
59 test "change/0 skips if Pleroma.Formatter is empty", %{migration: migration} do
60 assert :skipped == migration.change()
61 end
62 end