Merge branch 'release/listener' into 'develop'
[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 setup do
9 dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
10
11 Pleroma.Config.put([:instance, :dynamic_configuration], true)
12
13 on_exit(fn ->
14 Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
15 end)
16 end
17
18 test "transfer config values from db to env" do
19 refute Application.get_env(:pleroma, :test_key)
20 refute Application.get_env(:idna, :test_key)
21
22 Pleroma.Web.AdminAPI.Config.create(%{
23 group: "pleroma",
24 key: "test_key",
25 value: [live: 2, com: 3]
26 })
27
28 Pleroma.Web.AdminAPI.Config.create(%{
29 group: "idna",
30 key: "test_key",
31 value: [live: 15, com: 35]
32 })
33
34 Pleroma.Config.TransferTask.start_link()
35
36 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
37 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
38
39 on_exit(fn ->
40 Application.delete_env(:pleroma, :test_key)
41 Application.delete_env(:idna, :test_key)
42 end)
43 end
44
45 test "non existing atom" do
46 Pleroma.Web.AdminAPI.Config.create(%{
47 group: "pleroma",
48 key: "undefined_atom_key",
49 value: [live: 2, com: 3]
50 })
51
52 assert ExUnit.CaptureLog.capture_log(fn ->
53 Pleroma.Config.TransferTask.start_link()
54 end) =~
55 "updating env causes error, key: \"undefined_atom_key\", error: %ArgumentError{message: \"argument error\"}"
56 end
57 end