added test
authorMaksim Pechnikov <parallel588@gmail.com>
Fri, 7 Aug 2020 06:47:05 +0000 (09:47 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Fri, 7 Aug 2020 06:47:05 +0000 (09:47 +0300)
config/description.exs
test/web/admin_api/controllers/config_controller_test.exs

index 7da01b175d8728a27e62e6eb825ea2473ce7aa62..ac43bc814599bcfdf747a01d249ed6d90911ab79 100644 (file)
@@ -982,8 +982,7 @@ config :pleroma, :config_description, [
           %{
             key: :message,
             type: :string,
-            description:
-              "A message that will be sent to newly registered users",
+            description: "A message that will be sent to newly registered users",
             suggestions: [
               "Hi, @username! Welcome on board!"
             ]
@@ -3552,13 +3551,15 @@ config :pleroma, :config_description, [
             key: "name",
             label: "Name",
             type: :string,
-            description: "Name of the installed primary frontend. Valid config must include both `Name` and `Reference` values."
+            description:
+              "Name of the installed primary frontend. Valid config must include both `Name` and `Reference` values."
           },
           %{
             key: "ref",
             label: "Reference",
             type: :string,
-            description: "Reference of the installed primary frontend to be used. Valid config must include both `Name` and `Reference` values."
+            description:
+              "Reference of the installed primary frontend to be used. Valid config must include both `Name` and `Reference` values."
           }
         ]
       }
index 61bc9fd39093616ca0cd4db2361b7950cd03f87d..4e897455f03bbc0b241fa04052898def8556639e 100644 (file)
@@ -1342,6 +1342,75 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
                args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
              ]
     end
+
+    test "enables the welcome messages", %{conn: conn} do
+      clear_config([:welcome])
+
+      params = %{
+        "group" => ":pleroma",
+        "key" => ":welcome",
+        "value" => [
+          %{
+            "tuple" => [
+              ":direct_message",
+              [
+                %{"tuple" => [":enabled", true]},
+                %{"tuple" => [":message", "Welcome to Pleroma!"]},
+                %{"tuple" => [":sender_nickname", "pleroma"]}
+              ]
+            ]
+          },
+          %{
+            "tuple" => [
+              ":chat_message",
+              [
+                %{"tuple" => [":enabled", true]},
+                %{"tuple" => [":message", "Welcome to Pleroma!"]},
+                %{"tuple" => [":sender_nickname", "pleroma"]}
+              ]
+            ]
+          },
+          %{
+            "tuple" => [
+              ":email",
+              [
+                %{"tuple" => [":enabled", true]},
+                %{"tuple" => [":sender", %{"tuple" => ["pleroma@dev.dev", "Pleroma"]}]},
+                %{"tuple" => [":subject", "Welcome to <%= instance_name %>!"]},
+                %{"tuple" => [":html", "Welcome to <%= instance_name %>!"]},
+                %{"tuple" => [":text", "Welcome to <%= instance_name %>!"]}
+              ]
+            ]
+          }
+        ]
+      }
+
+      refute Pleroma.User.WelcomeEmail.enabled?()
+      refute Pleroma.User.WelcomeMessage.enabled?()
+      refute Pleroma.User.WelcomeChatMessage.enabled?()
+
+      res =
+        assert conn
+               |> put_req_header("content-type", "application/json")
+               |> post("/api/pleroma/admin/config", %{"configs" => [params]})
+               |> json_response_and_validate_schema(200)
+
+      assert Pleroma.User.WelcomeEmail.enabled?()
+      assert Pleroma.User.WelcomeMessage.enabled?()
+      assert Pleroma.User.WelcomeChatMessage.enabled?()
+
+      assert res == %{
+               "configs" => [
+                 %{
+                   "db" => [":direct_message", ":chat_message", ":email"],
+                   "group" => ":pleroma",
+                   "key" => ":welcome",
+                   "value" => params["value"]
+                 }
+               ],
+               "need_reboot" => false
+             }
+    end
   end
 
   describe "GET /api/pleroma/admin/config/descriptions" do