changes after rebase
[akkoma] / test / pleroma / repo / migrations / autolinker_to_linkify_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8 import Pleroma.Tests.Helpers
9 alias Pleroma.ConfigDB
10
11 setup do: clear_config(Pleroma.Formatter)
12 setup_all do: require_migration("20200716195806_autolinker_to_linkify")
13
14 test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: migration} do
15 autolinker_opts = [
16 extra: true,
17 validate_tld: true,
18 class: false,
19 strip_prefix: false,
20 new_window: false,
21 rel: "testing"
22 ]
23
24 insert(:config, group: :auto_linker, key: :opts, value: autolinker_opts)
25
26 migration.change()
27
28 assert nil == ConfigDB.get_by_params(%{group: :auto_linker, key: :opts})
29
30 %{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
31
32 assert new_opts == [
33 class: false,
34 extra: true,
35 new_window: false,
36 rel: "testing",
37 strip_prefix: false
38 ]
39
40 Pleroma.Config.put(Pleroma.Formatter, new_opts)
41 assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
42
43 {text, _mentions, []} =
44 Pleroma.Formatter.linkify(
45 "https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???"
46 )
47
48 assert text ==
49 "<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???"
50 end
51
52 test "transform_opts/1 returns a list of compatible opts", %{migration: migration} do
53 old_opts = [
54 extra: true,
55 validate_tld: true,
56 class: false,
57 strip_prefix: false,
58 new_window: false,
59 rel: "qqq"
60 ]
61
62 expected_opts = [
63 class: false,
64 extra: true,
65 new_window: false,
66 rel: "qqq",
67 strip_prefix: false
68 ]
69
70 assert migration.transform_opts(old_opts) == expected_opts
71 end
72 end