Add spec for AccountController.follow
authorEgor Kislitsyn <egor@kislitsyn.com>
Thu, 9 Apr 2020 11:25:24 +0000 (15:25 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 13 Apr 2020 14:17:08 +0000 (18:17 +0400)
lib/pleroma/web/api_spec.ex
lib/pleroma/web/api_spec/operations/account_operation.ex
lib/pleroma/web/api_spec/schemas/account_relationship.ex [moved from lib/pleroma/web/api_spec/schemas/account_relationship_response.ex with 71% similarity]
lib/pleroma/web/api_spec/schemas/account_relationships_response.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
test/web/mastodon_api/controllers/account_controller_test.exs

index d11e776d08bd3d2c84fff5f4ea5ec9566dfb0658..b3c1e3ea24e7a403b4202893e0f96a3330f0b561 100644 (file)
@@ -39,7 +39,7 @@ defmodule Pleroma.Web.ApiSpec do
               password: %OpenApiSpex.OAuthFlow{
                 authorizationUrl: "/oauth/authorize",
                 tokenUrl: "/oauth/token",
-                scopes: %{"read" => "read", "write" => "write"}
+                scopes: %{"read" => "read", "write" => "write", "follow" => "follow"}
               }
             }
           }
index ad10f4ec9dd201646d9f50c444cd427441274505..a76141f7aef86dc67a032e257ebeb775013f603f 100644 (file)
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
   alias Pleroma.Web.ApiSpec.Schemas.Account
   alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
   alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
+  alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
   alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
   alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
   alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
@@ -186,9 +187,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           "Limit"
         )
       ],
-      responses: %{
-        200 => Operation.response("Accounts", "application/json", AccountsResponse)
-      }
+      responses: %{200 => Operation.response("Accounts", "application/json", AccountsResponse)}
     }
   end
 
@@ -199,16 +198,33 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
       operationId: "AccountController.lists",
       security: [%{"oAuth" => ["read:lists"]}],
       description: "User lists that you have added this account to.",
+      parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
+      responses: %{200 => Operation.response("Lists", "application/json", ListsResponse)}
+    }
+  end
+
+  def follow_operation do
+    %Operation{
+      tags: ["accounts"],
+      summary: "Follow",
+      operationId: "AccountController.follow",
+      security: [%{"oAuth" => ["follow", "write:follows"]}],
+      description: "Follow the given account",
       parameters: [
-        %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}
+        %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
+        Operation.parameter(
+          :reblogs,
+          :query,
+          BooleanLike,
+          "Receive this account's reblogs in home timeline? Defaults to true."
+        )
       ],
       responses: %{
-        200 => Operation.response("Lists", "application/json", ListsResponse)
+        200 => Operation.response("Relationship", "application/json", AccountRelationship)
       }
     }
   end
 
-  def follow_operation, do: :ok
   def unfollow_operation, do: :ok
   def mute_operation, do: :ok
   def unmute_operation, do: :ok
similarity index 71%
rename from lib/pleroma/web/api_spec/schemas/account_relationship_response.ex
rename to lib/pleroma/web/api_spec/schemas/account_relationship.ex
index 9974b946bf8604489fede411ab732da96f3118c2..7db3b49bb4a853d89436acd3fc3c402bb061faf0 100644 (file)
@@ -2,41 +2,43 @@
 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipResponse do
+defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
   alias OpenApiSpex.Schema
 
   require OpenApiSpex
 
   OpenApiSpex.schema(%{
-    title: "AccountRelationshipResponse",
-    description: "Response schema for an account relationship",
+    title: "AccountRelationship",
+    description: "Response schema for relationship",
     type: :object,
     properties: %{
-      id: %Schema{type: :string},
-      following: %Schema{type: :boolean},
-      showing_reblogs: %Schema{type: :boolean},
-      followed_by: %Schema{type: :boolean},
-      blocking: %Schema{type: :boolean},
       blocked_by: %Schema{type: :boolean},
+      blocking: %Schema{type: :boolean},
+      domain_blocking: %Schema{type: :boolean},
+      endorsed: %Schema{type: :boolean},
+      followed_by: %Schema{type: :boolean},
+      following: %Schema{type: :boolean},
+      id: %Schema{type: :string},
       muting: %Schema{type: :boolean},
       muting_notifications: %Schema{type: :boolean},
       requested: %Schema{type: :boolean},
-      domain_blocking: %Schema{type: :boolean},
-      endorsed: %Schema{type: :boolean}
+      showing_reblogs: %Schema{type: :boolean},
+      subscribing: %Schema{type: :boolean}
     },
     example: %{
       "JSON" => %{
-        "id" => "1",
-        "following" => true,
-        "showing_reblogs" => true,
-        "followed_by" => true,
-        "blocking" => false,
         "blocked_by" => false,
+        "blocking" => false,
+        "domain_blocking" => false,
+        "endorsed" => false,
+        "followed_by" => false,
+        "following" => false,
+        "id" => "9tKi3esbG7OQgZ2920",
         "muting" => false,
         "muting_notifications" => false,
         "requested" => false,
-        "domain_blocking" => false,
-        "endorsed" => false
+        "showing_reblogs" => true,
+        "subscribing" => false
       }
     }
   })
index 2ca632310170867b6b2a74c3bcadbe6d34114bed..960e14db12b318277cdf48e75c9e138ec5ecde3b 100644 (file)
@@ -9,7 +9,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
     title: "AccountRelationshipsResponse",
     description: "Response schema for account relationships",
     type: :array,
-    items: Pleroma.Web.ApiSpec.Schemas.AccountRelationshipResponse,
+    items: Pleroma.Web.ApiSpec.Schemas.AccountRelationship,
     example: [
       %{
         "id" => "1",
@@ -22,6 +22,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
         "muting_notifications" => false,
         "requested" => false,
         "domain_blocking" => false,
+        "subscribing" => false,
         "endorsed" => true
       },
       %{
@@ -35,6 +36,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
         "muting_notifications" => false,
         "requested" => true,
         "domain_blocking" => false,
+        "subscribing" => false,
         "endorsed" => false
       },
       %{
@@ -48,6 +50,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse do
         "muting_notifications" => false,
         "requested" => false,
         "domain_blocking" => true,
+        "subscribing" => true,
         "endorsed" => false
       }
     ]
index 2c5cd8cdec3a110ee3226cf8f5e20dc2b2f46849..d2ad65ef39c1fbdbc30015ecdddadc3d18bd821a 100644 (file)
@@ -92,7 +92,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
            :statuses,
            :followers,
            :following,
-           :lists
+           :lists,
+           :follow
          ]
   )
 
@@ -337,8 +338,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
     {:error, :not_found}
   end
 
-  def follow(%{assigns: %{user: follower, account: followed}} = conn, _params) do
-    with {:ok, follower} <- MastodonAPI.follow(follower, followed, conn.params) do
+  def follow(%{assigns: %{user: follower, account: followed}} = conn, params) do
+    with {:ok, follower} <- MastodonAPI.follow(follower, followed, params) do
       render(conn, "relationship.json", user: follower, target: followed)
     else
       {:error, message} -> json_response(conn, :forbidden, %{error: message})
index 706eea5d93857a4fdfab6a9184ac68d48ac5628a..7a3d5860007729cfe299a5e1095d9512a4f47ac4 100644 (file)
@@ -669,6 +669,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
 
       assert %{"id" => id} = json_response(conn, 200)
       assert id == to_string(other_user.id)
+      assert_schema(json_response(conn, 200), "AccountRelationship", ApiSpec.spec())
     end
 
     test "cancelling follow request", %{conn: conn} do