Add specs for ActorType and VisibilityScope
authorEgor Kislitsyn <egor@kislitsyn.com>
Tue, 7 Apr 2020 12:18:23 +0000 (16:18 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 13 Apr 2020 14:16:07 +0000 (18:16 +0400)
lib/pleroma/web/api_spec/schemas/account.ex
lib/pleroma/web/api_spec/schemas/account_update_credentials_request.ex
lib/pleroma/web/api_spec/schemas/actor_type.ex [new file with mode: 0644]
lib/pleroma/web/api_spec/schemas/visibility_scope.ex [new file with mode: 0644]
test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs

index 59c4ac4a4b52144ebef3ff1ce94a439882291a9b..beb0931824a027ce58ce07e81c875817954f4dfe 100644 (file)
@@ -6,6 +6,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
   alias OpenApiSpex.Schema
   alias Pleroma.Web.ApiSpec.Schemas.AccountEmoji
   alias Pleroma.Web.ApiSpec.Schemas.AccountField
+  alias Pleroma.Web.ApiSpec.Schemas.ActorType
+  alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
 
   require OpenApiSpex
 
@@ -87,12 +89,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
         properties: %{
           fields: %Schema{type: :array, items: AccountField},
           note: %Schema{type: :string},
-          privacy: %Schema{type: :string},
+          privacy: VisibilityScope,
           sensitive: %Schema{type: :boolean},
           pleroma: %Schema{
             type: :object,
             properties: %{
-              actor_type: %Schema{type: :string},
+              actor_type: ActorType,
               discoverable: %Schema{type: :boolean},
               no_rich_text: %Schema{type: :boolean},
               show_role: %Schema{type: :boolean}
index a50bce5edc4a72e11652c3dea49c12eff65f08b4..6ab48193edf577828b81823ef4f9761d4a977882 100644 (file)
@@ -5,6 +5,8 @@
 defmodule Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest do
   alias OpenApiSpex.Schema
   alias Pleroma.Web.ApiSpec.Schemas.AccountAttributeField
+  alias Pleroma.Web.ApiSpec.Schemas.ActorType
+  alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
   require OpenApiSpex
 
   OpenApiSpex.schema(%{
@@ -73,10 +75,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest do
         description: "user's role (e.g admin, moderator) will be exposed to anyone in the
       API"
       },
-      default_scope: %Schema{
-        type: :string,
-        description: "The scope returned under privacy key in Source subentity"
-      },
+      default_scope: VisibilityScope,
       pleroma_settings_store: %Schema{
         type: :object,
         description: "Opaque user settings to be saved on the backend."
@@ -98,7 +97,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest do
         type: :boolean,
         description: "Discovery of this account in search results and other services is allowed."
       },
-      actor_type: %Schema{type: :string, description: "the type of this account."}
+      actor_type: ActorType
     },
     example: %{
       bot: false,
diff --git a/lib/pleroma/web/api_spec/schemas/actor_type.ex b/lib/pleroma/web/api_spec/schemas/actor_type.ex
new file mode 100644 (file)
index 0000000..ac9b466
--- /dev/null
@@ -0,0 +1,13 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ApiSpec.Schemas.ActorType do
+  require OpenApiSpex
+
+  OpenApiSpex.schema(%{
+    title: "ActorType",
+    type: :string,
+    enum: ["Application", "Group", "Organization", "Person", "Service"]
+  })
+end
diff --git a/lib/pleroma/web/api_spec/schemas/visibility_scope.ex b/lib/pleroma/web/api_spec/schemas/visibility_scope.ex
new file mode 100644 (file)
index 0000000..8c81a4d
--- /dev/null
@@ -0,0 +1,14 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ApiSpec.Schemas.VisibilityScope do
+  require OpenApiSpex
+
+  OpenApiSpex.schema(%{
+    title: "VisibilityScope",
+    description: "Status visibility",
+    type: :string,
+    enum: ["public", "unlisted", "private", "direct"]
+  })
+end
index 0e890a9807125a2c84c31df2001204fac06602a3..a3356c12f4e001d1fb126959fff1246cbc2cd5ff 100644 (file)
@@ -106,10 +106,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
     end
 
     test "updates the user's default scope", %{conn: conn} do
-      conn = patch(conn, "/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
+      conn = patch(conn, "/api/v1/accounts/update_credentials", %{default_scope: "unlisted"})
 
       assert user_data = json_response(conn, 200)
-      assert user_data["source"]["privacy"] == "cofe"
+      assert user_data["source"]["privacy"] == "unlisted"
     end
 
     test "updates the user's hide_followers status", %{conn: conn} do