2020-10-12 17:00:50 +00:00
# Pleroma: A lightweight social networking server
2022-02-26 06:11:42 +00:00
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2020-10-12 17:00:50 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
2020-07-22 18:10:10 +00:00
defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
use Pleroma.DataCase
import Pleroma.Factory
2020-07-22 21:01:55 +00:00
import Pleroma.Tests.Helpers
2020-07-22 18:10:10 +00:00
alias Pleroma.ConfigDB
2020-07-22 21:01:55 +00:00
setup do : clear_config ( Pleroma.Formatter )
2020-07-22 18:45:15 +00:00
setup_all do : require_migration ( " 20200716195806_autolinker_to_linkify " )
2020-07-22 18:10:10 +00:00
test " change/0 converts auto_linker opts for Pleroma.Formatter " , %{ migration : migration } do
autolinker_opts = [
extra : true ,
validate_tld : true ,
class : false ,
strip_prefix : false ,
new_window : false ,
2020-07-22 21:01:55 +00:00
rel : " testing "
2020-07-22 18:10:10 +00:00
]
insert ( :config , group : :auto_linker , key : :opts , value : autolinker_opts )
migration . change ( )
assert nil == ConfigDB . get_by_params ( %{ group : :auto_linker , key : :opts } )
%{ value : new_opts } = ConfigDB . get_by_params ( %{ group : :pleroma , key : Pleroma.Formatter } )
assert new_opts == [
class : false ,
extra : true ,
new_window : false ,
2020-07-22 21:01:55 +00:00
rel : " testing " ,
2020-07-22 18:10:10 +00:00
strip_prefix : false
]
2021-01-26 17:58:43 +00:00
clear_config ( Pleroma.Formatter , new_opts )
2020-07-22 21:01:55 +00:00
assert new_opts == Pleroma.Config . get ( Pleroma.Formatter )
2020-07-22 18:10:10 +00:00
{ text , _mentions , [ ] } =
Pleroma.Formatter . linkify (
" https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7 \n \n Omg will COVID finally end Black Friday??? "
)
assert text ==
2020-07-22 21:01:55 +00:00
" <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 \n Omg will COVID finally end Black Friday??? "
2020-07-22 18:10:10 +00:00
end
test " transform_opts/1 returns a list of compatible opts " , %{ migration : migration } do
old_opts = [
extra : true ,
validate_tld : true ,
class : false ,
strip_prefix : false ,
new_window : false ,
2020-07-22 21:01:55 +00:00
rel : " qqq "
2020-07-22 18:10:10 +00:00
]
expected_opts = [
class : false ,
extra : true ,
new_window : false ,
2020-07-22 21:01:55 +00:00
rel : " qqq " ,
2020-07-22 18:10:10 +00:00
strip_prefix : false
]
assert migration . transform_opts ( old_opts ) == expected_opts
end
end