Merge branch 'bind-to-localhost' into 'develop'
[akkoma] / test / config / transfer_task_test.exs
1 defmodule Pleroma.Config.TransferTaskTest do
2 use Pleroma.DataCase
3
4 setup do
5 dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
6
7 Pleroma.Config.put([:instance, :dynamic_configuration], true)
8
9 on_exit(fn ->
10 Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
11 end)
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
18 Pleroma.Web.AdminAPI.Config.create(%{
19 group: "pleroma",
20 key: "test_key",
21 value: [live: 2, com: 3]
22 })
23
24 Pleroma.Web.AdminAPI.Config.create(%{
25 group: "idna",
26 key: "test_key",
27 value: [live: 15, com: 35]
28 })
29
30 Pleroma.Config.TransferTask.start_link()
31
32 assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
33 assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
34
35 on_exit(fn ->
36 Application.delete_env(:pleroma, :test_key)
37 Application.delete_env(:idna, :test_key)
38 end)
39 end
40
41 test "non existing atom" do
42 Pleroma.Web.AdminAPI.Config.create(%{
43 group: "pleroma",
44 key: "undefined_atom_key",
45 value: [live: 2, com: 3]
46 })
47
48 assert ExUnit.CaptureLog.capture_log(fn ->
49 Pleroma.Config.TransferTask.start_link()
50 end) =~
51 "updating env causes error, key: \"undefined_atom_key\", error: %ArgumentError{message: \"argument error\"}"
52 end
53 end