return db key on update requests
[akkoma] / test / config / transfer_task_test.exs
index 4b3dd8bbda119c065c4a8fb8c0d346b2589e2a1a..37bea20a3439f5d49f1cb1344889fa1125210ac7 100644 (file)
@@ -5,39 +5,79 @@
 defmodule Pleroma.Config.TransferTaskTest do
   use Pleroma.DataCase
 
-  clear_config([:instance, :dynamic_configuration]) do
-    Pleroma.Config.put([:instance, :dynamic_configuration], true)
+  alias Pleroma.ConfigDB
+
+  clear_config(:configurable_from_database) do
+    Pleroma.Config.put(:configurable_from_database, true)
   end
 
   test "transfer config values from db to env" do
     refute Application.get_env(:pleroma, :test_key)
     refute Application.get_env(:idna, :test_key)
+    refute Application.get_env(:quack, :test_key)
 
-    Pleroma.Web.AdminAPI.Config.create(%{
+    ConfigDB.create(%{
       group: ":pleroma",
       key: ":test_key",
       value: [live: 2, com: 3]
     })
 
-    Pleroma.Web.AdminAPI.Config.create(%{
+    ConfigDB.create(%{
       group: ":idna",
       key: ":test_key",
       value: [live: 15, com: 35]
     })
 
+    ConfigDB.create(%{
+      group: ":quack",
+      key: ":test_key",
+      value: [:test_value1, :test_value2]
+    })
+
     Pleroma.Config.TransferTask.start_link([])
 
     assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
     assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
+    assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
 
     on_exit(fn ->
       Application.delete_env(:pleroma, :test_key)
       Application.delete_env(:idna, :test_key)
+      Application.delete_env(:quack, :test_key)
+    end)
+  end
+
+  test "transfer config values for 1 group and some keys" do
+    level = Application.get_env(:quack, :level)
+    meta = Application.get_env(:quack, :meta)
+
+    ConfigDB.create(%{
+      group: ":quack",
+      key: ":level",
+      value: :info
+    })
+
+    ConfigDB.create(%{
+      group: ":quack",
+      key: ":meta",
+      value: [:none]
+    })
+
+    Pleroma.Config.TransferTask.start_link([])
+
+    assert Application.get_env(:quack, :level) == :info
+    assert Application.get_env(:quack, :meta) == [:none]
+    default = Pleroma.Config.Holder.config(:quack, :webhook_url)
+    assert Application.get_env(:quack, :webhook_url) == default
+
+    on_exit(fn ->
+      Application.put_env(:quack, :level, level)
+      Application.put_env(:quack, :meta, meta)
     end)
   end
 
   test "non existing atom" do
-    Pleroma.Web.AdminAPI.Config.create(%{
+    ConfigDB.create(%{
       group: ":pleroma",
       key: ":undefined_atom_key",
       value: [live: 2, com: 3]
@@ -46,6 +86,6 @@ defmodule Pleroma.Config.TransferTaskTest do
     assert ExUnit.CaptureLog.capture_log(fn ->
              Pleroma.Config.TransferTask.start_link([])
            end) =~
-             "updating env causes error, key: \":undefined_atom_key\", error: %ArgumentError{message: \"argument error\"}"
+             "updating env causes error, group: \":pleroma\", key: \":undefined_atom_key\", value: [live: 2, com: 3], error: %ArgumentError{message: \"argument error\"}"
   end
 end