clients.md: Add Kyclos
[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.Config.TransferTask
9 alias Pleroma.ConfigDB
10
11 clear_config(:configurable_from_database) do
12 Pleroma.Config.put(:configurable_from_database, true)
13 end
14
15 test "transfer config values from db to env" do
16 refute Application.get_env(:pleroma, :test_key)
17 refute Application.get_env(:idna, :test_key)
18 refute Application.get_env(:quack, :test_key)
19
20 ConfigDB.create(%{
21 group: ":pleroma",
22 key: ":test_key",
23 value: [live: 2, com: 3]
24 })
25
26 ConfigDB.create(%{
27 group: ":idna",
28 key: ":test_key",
29 value: [live: 15, com: 35]
30 })
31
32 ConfigDB.create(%{
33 group: ":quack",
34 key: ":test_key",
35 value: [:test_value1, :test_value2]
36 })
37
38 TransferTask.start_link([])
39
40 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
41 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
42 assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
43
44 on_exit(fn ->
45 Application.delete_env(:pleroma, :test_key)
46 Application.delete_env(:idna, :test_key)
47 Application.delete_env(:quack, :test_key)
48 end)
49 end
50
51 test "transfer config values for 1 group and some keys" do
52 level = Application.get_env(:quack, :level)
53 meta = Application.get_env(:quack, :meta)
54
55 ConfigDB.create(%{
56 group: ":quack",
57 key: ":level",
58 value: :info
59 })
60
61 ConfigDB.create(%{
62 group: ":quack",
63 key: ":meta",
64 value: [:none]
65 })
66
67 TransferTask.start_link([])
68
69 assert Application.get_env(:quack, :level) == :info
70 assert Application.get_env(:quack, :meta) == [:none]
71 default = Pleroma.Config.Holder.config(:quack, :webhook_url)
72 assert Application.get_env(:quack, :webhook_url) == default
73
74 on_exit(fn ->
75 Application.put_env(:quack, :level, level)
76 Application.put_env(:quack, :meta, meta)
77 end)
78 end
79
80 test "transfer config values with full subkey update" do
81 emoji = Application.get_env(:pleroma, :emoji)
82 assets = Application.get_env(:pleroma, :assets)
83
84 ConfigDB.create(%{
85 group: ":pleroma",
86 key: ":emoji",
87 value: [groups: [a: 1, b: 2]]
88 })
89
90 ConfigDB.create(%{
91 group: ":pleroma",
92 key: ":assets",
93 value: [mascots: [a: 1, b: 2]]
94 })
95
96 TransferTask.start_link([])
97
98 emoji_env = Application.get_env(:pleroma, :emoji)
99 assert emoji_env[:groups] == [a: 1, b: 2]
100 assets_env = Application.get_env(:pleroma, :assets)
101 assert assets_env[:mascots] == [a: 1, b: 2]
102
103 on_exit(fn ->
104 Application.put_env(:pleroma, :emoji, emoji)
105 Application.put_env(:pleroma, :assets, assets)
106 end)
107 end
108 end