end
describe "GET /api/pleroma/admin/config" do
- setup %{conn: conn} do
- admin = insert(:user, is_admin: true)
-
- %{conn: assign(conn, :user, admin)}
- end
-
+ clear_config([:configurable_from_database]) do
+ Pleroma.Config.put([:configurable_from_database], true)
+ end
+
+ test "when configuration from database is off", %{conn: conn} do
+ initial = Pleroma.Config.get([:configurable_from_database])
+ Pleroma.Config.put([:configurable_from_database], false)
+ on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end)
+ conn = get(conn, "/api/pleroma/admin/config")
+
+ assert json_response(conn, 400) ==
+ "To use this endpoint you need to enable configuration from database."
+ end
+
test "without any settings in db", %{conn: conn} do
conn = get(conn, "/api/pleroma/admin/config")
end
end
- test "POST /api/pleroma/admin/config error" do
- admin = insert(:user, is_admin: true)
-
- conn =
- build_conn()
- |> assign(:user, admin)
- |> post("/api/pleroma/admin/config", %{"configs" => []})
++ test "POST /api/pleroma/admin/config error", %{conn: conn} do
++ conn = post(conn, "/api/pleroma/admin/config", %{"configs" => []})
+
+ assert json_response(conn, 400) ==
+ "To use this endpoint you need to enable configuration from database."
+ end
+
describe "POST /api/pleroma/admin/config" do
- setup %{conn: conn} do
- admin = insert(:user, is_admin: true)
-
+ setup do
- temp_file = "config/test.exported_from_db.secret.exs"
+ http = Application.get_env(:pleroma, :http)
on_exit(fn ->
Application.delete_env(:pleroma, :key1)
Application.delete_env(:pleroma, :keyaa2)
Application.delete_env(:pleroma, Pleroma.Web.Endpoint.NotReal)
Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)
- :ok = File.rm(temp_file)
+ Application.put_env(:pleroma, :http, http)
+ Application.put_env(:tesla, :adapter, Tesla.Mock)
+ :ok = File.rm("config/test.exported_from_db.secret.exs")
end)
-
- %{conn: assign(conn, :user, admin)}
end
- clear_config([:instance, :dynamic_configuration]) do
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ clear_config([:configurable_from_database]) do
+ Pleroma.Config.put([:configurable_from_database], true)
end
@tag capture_log: true
end
describe "config mix tasks run" do
- setup %{conn: conn} do
- admin = insert(:user, is_admin: true)
-
+ setup do
- temp_file = "config/test.exported_from_db.secret.exs"
-
Mix.shell(Mix.Shell.Quiet)
on_exit(fn ->
Mix.shell(Mix.Shell.IO)
- :ok = File.rm(temp_file)
end)
- %{conn: assign(conn, :user, admin)}
+ :ok
end
- clear_config([:instance, :dynamic_configuration]) do
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ clear_config([:configurable_from_database]) do
+ Pleroma.Config.put([:configurable_from_database], true)
end
clear_config([:feed, :post_title]) do
end
test "transfer settings to DB and to file", %{conn: conn} do
- assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
- ret_conn = get(conn, "/api/pleroma/admin/config/migrate_to_db")
- assert json_response(ret_conn, 200) == %{}
- assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) > 0
+ on_exit(fn -> :ok = File.rm("config/test.exported_from_db.secret.exs") end)
+ assert Repo.all(Pleroma.Web.AdminAPI.Config) == []
+ Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
+ assert Repo.aggregate(Pleroma.Web.AdminAPI.Config, :count, :id) > 0
+
+ conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
+
+ assert json_response(conn, 200) == %{}
+ assert Repo.all(Pleroma.Web.AdminAPI.Config) == []
+ end
+
+ test "returns error if configuration from database is off", %{conn: conn} do
+ initial = Pleroma.Config.get([:configurable_from_database])
+ on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end)
+ Pleroma.Config.put([:configurable_from_database], false)
+
+ conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
- ret_conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
+ assert json_response(conn, 400) ==
+ "To use this endpoint you need to enable configuration from database."
+
- assert json_response(ret_conn, 200) == %{}
- assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
++ assert Repo.all(Pleroma.Web.AdminAPI.Config) == []
end
end