Small wrapper module around Application.get_env/put_env
[akkoma] / test / config_test.exs
index 6d0f0a2d427fe2d59093f5bca964fc0b5a536194..32d5cc90c082c253c0424cec066610797cd4b53d 100644 (file)
@@ -1,10 +1,39 @@
 defmodule Pleroma.ConfigTest do
-  use Pleroma.DataCase
-  alias Pleroma.Config
+  use ExUnit.Case
 
-  test "get returns the item at the path if there is one" do
-    Config.put([:instance, :name], "Plemora")
-    assert Config.get([:instance, :name]) == "Plemora"
-    assert Config.get([:unknown]) == nil
+  test "get/1 with an atom" do
+    assert Pleroma.Config.get(:instance) == Application.get_env(:pleroma, :instance)
+    assert Pleroma.Config.get(:azertyuiop) == nil
+  end
+
+  test "get/1 with a list of keys" do
+    assert Pleroma.Config.get([:instance, :public]) ==
+             Keyword.get(Application.get_env(:pleroma, :instance), :public)
+
+    assert Pleroma.Config.get([Pleroma.Web.Endpoint, :render_errors, :view]) ==
+             get_in(
+               Application.get_env(
+                 :pleroma,
+                 Pleroma.Web.Endpoint
+               ),
+               [:render_errors, :view]
+             )
+
+    assert Pleroma.Config.get([:azerty, :uiop]) == nil
+  end
+
+  test "put/2 with a key" do
+    Pleroma.Config.put(:config_test, true)
+
+    assert Pleroma.Config.get(:config_test) == true
+  end
+
+  test "put/2 with a list of keys" do
+    Pleroma.Config.put([:instance, :config_test], true)
+    Pleroma.Config.put([:instance, :config_nested_test], [])
+    Pleroma.Config.put([:instance, :config_nested_test, :x], true)
+
+    assert Pleroma.Config.get([:instance, :config_test]) == true
+    assert Pleroma.Config.get([:instance, :config_nested_test, :x]) == true
   end
 end