saving to DB only added by user settings
[akkoma] / test / config / transfer_task_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Config.TransferTaskTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.ConfigDB
9
10 clear_config(:configurable_from_database) do
11 Pleroma.Config.put(:configurable_from_database, true)
12 end
13
14 test "transfer config values from db to env" do
15 refute Application.get_env(:pleroma, :test_key)
16 refute Application.get_env(:idna, :test_key)
17 refute Application.get_env(:quack, :test_key)
18
19 ConfigDB.create(%{
20 group: ":pleroma",
21 key: ":test_key",
22 value: [live: 2, com: 3]
23 })
24
25 ConfigDB.create(%{
26 group: ":idna",
27 key: ":test_key",
28 value: [live: 15, com: 35]
29 })
30
31 ConfigDB.create(%{
32 group: ":quack",
33 key: ":test_key",
34 value: [:test_value1, :test_value2]
35 })
36
37 Pleroma.Config.TransferTask.start_link([])
38
39 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
40 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
41 assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
42
43 on_exit(fn ->
44 Application.delete_env(:pleroma, :test_key)
45 Application.delete_env(:idna, :test_key)
46 Application.delete_env(:quack, :test_key)
47 end)
48 end
49
50 test "transfer config values for 1 group and some keys" do
51 level = Application.get_env(:quack, :level)
52 meta = Application.get_env(:quack, :meta)
53
54 ConfigDB.create(%{
55 group: ":quack",
56 key: ":level",
57 value: :info
58 })
59
60 ConfigDB.create(%{
61 group: ":quack",
62 key: ":meta",
63 value: [:none]
64 })
65
66 Pleroma.Config.TransferTask.start_link([])
67
68 assert Application.get_env(:quack, :level) == :info
69 assert Application.get_env(:quack, :meta) == [:none]
70 default = Pleroma.Config.Holder.config(:quack, :webhook_url)
71 assert Application.get_env(:quack, :webhook_url) == default
72
73 on_exit(fn ->
74 Application.put_env(:quack, :level, level)
75 Application.put_env(:quack, :meta, meta)
76 end)
77 end
78
79 test "non existing atom" do
80 ConfigDB.create(%{
81 group: ":pleroma",
82 key: ":undefined_atom_key",
83 value: [live: 2, com: 3]
84 })
85
86 assert ExUnit.CaptureLog.capture_log(fn ->
87 Pleroma.Config.TransferTask.start_link([])
88 end) =~
89 "updating env causes error, key: \":undefined_atom_key\", error: %ArgumentError{message: \"argument error\"}"
90 end
91 end