remove all endpoints marked as deprecated (#91)
authorfloatingghost <hannah@coffee-and-dreams.uk>
Wed, 20 Jul 2022 12:00:58 +0000 (12:00 +0000)
committerfloatingghost <hannah@coffee-and-dreams.uk>
Wed, 20 Jul 2022 12:00:58 +0000 (12:00 +0000)
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/91

17 files changed:
CHANGELOG.md
lib/pleroma/user.ex
lib/pleroma/web/api_spec/operations/chat_operation.ex
lib/pleroma/web/api_spec/operations/notification_operation.ex
lib/pleroma/web/api_spec/operations/search_operation.ex
lib/pleroma/web/api_spec/operations/status_operation.ex
lib/pleroma/web/auth/wrapper_authenticator.ex
lib/pleroma/web/mastodon_api/controllers/notification_controller.ex
lib/pleroma/web/mastodon_api/controllers/search_controller.ex
lib/pleroma/web/mastodon_api/controllers/status_controller.ex
lib/pleroma/web/rich_media/parsers/ogp.ex [deleted file]
lib/pleroma/web/router.ex
test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs
test/pleroma/web/mastodon_api/controllers/search_controller_test.exs
test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
test/support/helpers.ex

index a785508f4ffecd7842f1028c36dd2661bc59ea9f..3fe07f2902fe3b9286f93247dc60c7989cee32b5 100644 (file)
@@ -8,6 +8,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 ### Removed
 - Scrobbling support
+  - `/api/v1/pleroma/scrobble`
+  - `/api/v1/pleroma/accounts/{id}/scrobbles`
+- Deprecated endpoints
+  - `/api/v1/pleroma/chats`
+  - `/api/v1/notifications/dismiss`
+  - `/api/v1/search`
+  - `/api/v1/statuses/{id}/card` 
 
 ## 2022.07
 
index b256c87e1f7d36047488e2929fe03c534e9dd79c..a9caec55269cd69f864b72b658c25c8b650b4253 100644 (file)
@@ -194,17 +194,6 @@ defmodule Pleroma.User do
       has_many(incoming_relation_source, through: [incoming_relation, :source])
     end
 
-    # `:blocks` is deprecated (replaced with `blocked_users` relation)
-    field(:blocks, {:array, :string}, default: [])
-    # `:mutes` is deprecated (replaced with `muted_users` relation)
-    field(:mutes, {:array, :string}, default: [])
-    # `:muted_reblogs` is deprecated (replaced with `reblog_muted_users` relation)
-    field(:muted_reblogs, {:array, :string}, default: [])
-    # `:muted_notifications` is deprecated (replaced with `notification_muted_users` relation)
-    field(:muted_notifications, {:array, :string}, default: [])
-    # `:subscribers` is deprecated (replaced with `subscriber_users` relation)
-    field(:subscribers, {:array, :string}, default: [])
-
     embeds_one(
       :multi_factor_authentication_settings,
       MFA.Settings,
index 23cb66392b0cb32fc9981a1641ac78c7ea2fdd20..31fd150de4a8618fe0c22ae5d9d06592ff13506b 100644 (file)
@@ -128,28 +128,6 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
     }
   end
 
-  def index_operation do
-    %Operation{
-      tags: ["Chats"],
-      summary: "Retrieve list of chats (unpaginated)",
-      deprecated: true,
-      description:
-        "Deprecated due to no support for pagination. Using [/api/v2/pleroma/chats](#operation/ChatController.index2) instead is recommended.",
-      operationId: "ChatController.index",
-      parameters: [
-        Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users")
-      ],
-      responses: %{
-        200 => Operation.response("The chats of the user", "application/json", chats_response())
-      },
-      security: [
-        %{
-          "oAuth" => ["read:chats"]
-        }
-      ]
-    }
-  end
-
   def index2_operation do
     %Operation{
       tags: ["Chats"],
index e4ce42f1cf91540c2c0963950b0b255259551db9..01a886de35abd1680b215dc589fb6b3156805c16 100644 (file)
@@ -108,24 +108,6 @@ defmodule Pleroma.Web.ApiSpec.NotificationOperation do
     }
   end
 
-  def dismiss_via_body_operation do
-    %Operation{
-      tags: ["Notifications"],
-      summary: "Dismiss a single notification",
-      deprecated: true,
-      description: "Clear a single notification from the server.",
-      operationId: "NotificationController.dismiss_via_body",
-      requestBody:
-        request_body(
-          "Parameters",
-          %Schema{type: :object, properties: %{id: %Schema{type: :string}}},
-          required: true
-        ),
-      security: [%{"oAuth" => ["write:notifications"]}],
-      responses: %{200 => empty_object_response()}
-    }
-  end
-
   def destroy_multiple_operation do
     %Operation{
       tags: ["Notifications"],
index ff4fd002703e78ddb1e35057f86255275ede2e52..f90c548536c1b64a880ca2cc19c3b52a50f53b9a 100644 (file)
@@ -59,53 +59,6 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
     }
   end
 
-  def search_operation do
-    %Operation{
-      tags: ["Search"],
-      summary: "Search results",
-      security: [%{"oAuth" => ["read:search"]}],
-      operationId: "SearchController.search",
-      deprecated: true,
-      parameters: [
-        Operation.parameter(
-          :account_id,
-          :query,
-          FlakeID,
-          "If provided, statuses returned will be authored only by this account"
-        ),
-        Operation.parameter(
-          :type,
-          :query,
-          %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
-          "Search type"
-        ),
-        Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", required: true),
-        Operation.parameter(
-          :resolve,
-          :query,
-          %Schema{allOf: [BooleanLike], default: false},
-          "Attempt WebFinger lookup"
-        ),
-        Operation.parameter(
-          :following,
-          :query,
-          %Schema{allOf: [BooleanLike], default: false},
-          "Only include accounts that the user is following"
-        ),
-        Operation.parameter(
-          :offset,
-          :query,
-          %Schema{type: :integer},
-          "Offset"
-        ),
-        with_relationships_param() | pagination_params()
-      ],
-      responses: %{
-        200 => Operation.response("Results", "application/json", results())
-      }
-    }
-  end
-
   def search2_operation do
     %Operation{
       tags: ["Search"],
@@ -176,33 +129,4 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
       }
     }
   end
-
-  defp results do
-    %Schema{
-      title: "SearchResults",
-      type: :object,
-      properties: %{
-        accounts: %Schema{
-          type: :array,
-          items: Account,
-          description: "Accounts which match the given query"
-        },
-        statuses: %Schema{
-          type: :array,
-          items: Status,
-          description: "Statuses which match the given query"
-        },
-        hashtags: %Schema{
-          type: :array,
-          items: %Schema{type: :string},
-          description: "Hashtags which match the given query"
-        }
-      },
-      example: %{
-        "accounts" => [Account.schema().example],
-        "statuses" => [Status.schema().example],
-        "hashtags" => ["cofe"]
-      }
-    }
-  end
 end
index 802fbef3e90545a725d25e88a85afc7387b865e7..c7df676c34f846a4f7b35e952b864c295cf4168d 100644 (file)
@@ -323,34 +323,6 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
     }
   end
 
-  def card_operation do
-    %Operation{
-      tags: ["Retrieve status information"],
-      deprecated: true,
-      summary: "Preview card",
-      description: "Deprecated in favor of card property inlined on Status entity",
-      operationId: "StatusController.card",
-      parameters: [id_param()],
-      security: [%{"oAuth" => ["read:statuses"]}],
-      responses: %{
-        200 =>
-          Operation.response("Card", "application/json", %Schema{
-            type: :object,
-            nullable: true,
-            properties: %{
-              type: %Schema{type: :string, enum: ["link", "photo", "video", "rich"]},
-              provider_name: %Schema{type: :string, nullable: true},
-              provider_url: %Schema{type: :string, format: :uri},
-              url: %Schema{type: :string, format: :uri},
-              image: %Schema{type: :string, nullable: true, format: :uri},
-              title: %Schema{type: :string},
-              description: %Schema{type: :string}
-            }
-          })
-      }
-    }
-  end
-
   def favourited_by_operation do
     %Operation{
       tags: ["Retrieve status information"],
index c67082f7b3efbda8a1d6146a43c51b5f131e79fe..b8450872b7de2055a3d51213697f61cfc528760c 100644 (file)
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.Auth.WrapperAuthenticator do
   def auth_template do
     # Note: `config :pleroma, :auth_template, "..."` support is deprecated
     implementation().auth_template() ||
-      Pleroma.Config.get([:auth, :auth_template], Pleroma.Config.get(:auth_template)) ||
+      Pleroma.Config.get(:auth_template) ||
       "show.html"
   end
 
index 002d6b2cea48762b61eabc927cde7adfacc7da57..ae4432e85c3001b26ec901a2e31ffc4553c0fb91 100644 (file)
@@ -98,11 +98,6 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do
     end
   end
 
-  # POST /api/v1/notifications/dismiss (deprecated)
-  def dismiss_via_body(%{body_params: params} = conn, _) do
-    dismiss(conn, params)
-  end
-
   # DELETE /api/v1/notifications/destroy_multiple
   def destroy_multiple(%{assigns: %{user: user}} = conn, %{ids: ids} = _params) do
     Notification.destroy_multiple(user, ids)
index e4acba2264b1b2086e6720dcdc04ecdba1ac3456..bd12069c154131af4ad0a75487c371327760520e 100644 (file)
@@ -25,7 +25,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
 
   # Note: on private instances auth is required (EnsurePublicOrAuthenticatedPlug is not skipped)
 
-  plug(RateLimiter, [name: :search] when action in [:search, :search2, :account_search])
+  plug(RateLimiter, [name: :search] when action in [:search2, :account_search])
 
   defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.SearchOperation
 
@@ -42,7 +42,6 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
   end
 
   def search2(conn, params), do: do_search(:v2, conn, params)
-  def search(conn, params), do: do_search(:v1, conn, params)
 
   defp do_search(version, %{assigns: %{user: user}} = conn, %{q: query} = params) do
     query = String.trim(query)
@@ -118,10 +117,6 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
     end)
   end
 
-  defp resource_search(:v1, "hashtags", query, options) do
-    prepare_tags(query, options)
-  end
-
   defp prepare_tags(query, options) do
     tags =
       query
index 60f4c44d7c705ef7079fbf17439ab61a79bc6367..9ab30742bd16d6d87fe2adaaa02e6d3a3ef65041 100644 (file)
@@ -37,7 +37,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
     when action in [
            :index,
            :show,
-           :card,
            :context
          ]
   )
@@ -315,18 +314,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
     end
   end
 
-  @doc "GET /api/v1/statuses/:id/card"
-  @deprecated "https://github.com/tootsuite/mastodon/pull/11213"
-  def card(%{assigns: %{user: user}} = conn, %{id: status_id}) do
-    with %Activity{} = activity <- Activity.get_by_id(status_id),
-         true <- Visibility.visible_for_user?(activity, user) do
-      data = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
-      render(conn, "card.json", data)
-    else
-      _ -> render_error(conn, :not_found, "Record not found")
-    end
-  end
-
   @doc "GET /api/v1/statuses/:id/favourited_by"
   def favourited_by(%{assigns: %{user: user}} = conn, %{id: id}) do
     with true <- Pleroma.Config.get([:instance, :show_reactions]),
diff --git a/lib/pleroma/web/rich_media/parsers/ogp.ex b/lib/pleroma/web/rich_media/parsers/ogp.ex
deleted file mode 100644 (file)
index d0edf1c..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.RichMedia.Parsers.OGP do
-  @deprecated "OGP parser is deprecated. Use TwitterCard instead."
-  def parse(_html, _data) do
-    %{}
-  end
-end
index 9974e3dee6057588681b70e76ce411d2162409f6..8a53f770eb47f3ff7e9adab5b8080c256e8f1d07 100644 (file)
@@ -428,7 +428,6 @@ defmodule Pleroma.Web.Router do
       pipe_through(:authenticated_api)
 
       post("/chats/by-account-id/:id", ChatController, :create)
-      get("/chats", ChatController, :index)
       get("/chats/:id", ChatController, :show)
       get("/chats/:id/messages", ChatController, :messages)
       post("/chats/:id/messages", ChatController, :post_chat_message)
@@ -543,8 +542,6 @@ defmodule Pleroma.Web.Router do
     post("/notifications/:id/dismiss", NotificationController, :dismiss)
     post("/notifications/clear", NotificationController, :clear)
     delete("/notifications/destroy_multiple", NotificationController, :destroy_multiple)
-    # Deprecated: was removed in Mastodon v3, use `/notifications/:id/dismiss` instead
-    post("/notifications/dismiss", NotificationController, :dismiss_via_body)
 
     post("/polls/:id/votes", PollController, :vote)
 
@@ -607,8 +604,6 @@ defmodule Pleroma.Web.Router do
     pipe_through(:api)
 
     get("/accounts/search", SearchController, :account_search)
-    get("/search", SearchController, :search)
-
     get("/accounts/lookup", AccountController, :lookup)
 
     get("/accounts/:id/statuses", AccountController, :statuses)
@@ -624,7 +619,6 @@ defmodule Pleroma.Web.Router do
     get("/statuses", StatusController, :index)
     get("/statuses/:id", StatusController, :show)
     get("/statuses/:id/context", StatusController, :context)
-    get("/statuses/:id/card", StatusController, :card)
     get("/statuses/:id/favourited_by", StatusController, :favourited_by)
     get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
 
index d991f284f2fffe2b1f8a2cb6b3fe5542a5824368..6507835871f736694b756ad6bf0fc34c169c4e66 100644 (file)
@@ -137,23 +137,6 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
     assert response == expected_response
   end
 
-  test "dismissing a single notification (deprecated endpoint)" do
-    %{user: user, conn: conn} = oauth_access(["write:notifications"])
-    other_user = insert(:user)
-
-    {:ok, activity} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
-
-    {:ok, [notification]} = Notification.create_notifications(activity)
-
-    conn =
-      conn
-      |> assign(:user, user)
-      |> put_req_header("content-type", "application/json")
-      |> post("/api/v1/notifications/dismiss", %{"id" => to_string(notification.id)})
-
-    assert %{} = json_response_and_validate_schema(conn, 200)
-  end
-
   test "dismissing a single notification" do
     %{user: user, conn: conn} = oauth_access(["write:notifications"])
     other_user = insert(:user)
index e31cd0291fd0e264a8338ded17f77fc0b8dc60bd..fd29621961a2b0c70d8b287bd08f1aaf41c61b44 100644 (file)
@@ -5,7 +5,6 @@
 defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
   use Pleroma.Web.ConnCase
 
-  alias Pleroma.Object
   alias Pleroma.Web.CommonAPI
   alias Pleroma.Web.Endpoint
   import Pleroma.Factory
@@ -221,189 +220,4 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
       assert length(results) == 1
     end
   end
-
-  describe ".search" do
-    test "it returns empty result if user or status search return undefined error", %{conn: conn} do
-      with_mocks [
-        {Pleroma.User, [], [search: fn _q, _o -> raise "Oops" end]},
-        {Pleroma.Activity, [], [search: fn _u, _q, _o -> raise "Oops" end]}
-      ] do
-        capture_log(fn ->
-          results =
-            conn
-            |> get("/api/v1/search?q=2hu")
-            |> json_response_and_validate_schema(200)
-
-          assert results["accounts"] == []
-          assert results["statuses"] == []
-        end) =~
-          "[error] Elixir.Pleroma.Web.MastodonAPI.SearchController search error: %RuntimeError{message: \"Oops\"}"
-      end
-    end
-
-    test "search", %{conn: conn} do
-      user = insert(:user)
-      user_two = insert(:user, %{nickname: "shp@shitposter.club"})
-      user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
-
-      {:ok, activity} = CommonAPI.post(user, %{status: "This is about 2hu"})
-
-      {:ok, _activity} =
-        CommonAPI.post(user, %{
-          status: "This is about 2hu, but private",
-          visibility: "private"
-        })
-
-      {:ok, _} = CommonAPI.post(user_two, %{status: "This isn't"})
-
-      results =
-        conn
-        |> get("/api/v1/search?q=2hu")
-        |> json_response_and_validate_schema(200)
-
-      [account | _] = results["accounts"]
-      assert account["id"] == to_string(user_three.id)
-
-      assert results["hashtags"] == ["2hu"]
-
-      [status] = results["statuses"]
-      assert status["id"] == to_string(activity.id)
-    end
-
-    test "search fetches remote statuses and prefers them over other results", %{conn: conn} do
-      old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
-      :persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
-      on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
-
-      capture_log(fn ->
-        {:ok, %{id: activity_id}} =
-          CommonAPI.post(insert(:user), %{
-            status: "check out http://mastodon.example.org/@admin/99541947525187367"
-          })
-
-        results =
-          conn
-          |> get("/api/v1/search?q=http://mastodon.example.org/@admin/99541947525187367")
-          |> json_response_and_validate_schema(200)
-
-        assert [
-                 %{"url" => "http://mastodon.example.org/@admin/99541947525187367"},
-                 %{"id" => ^activity_id}
-               ] = results["statuses"]
-      end)
-    end
-
-    test "search doesn't show statuses that it shouldn't", %{conn: conn} do
-      {:ok, activity} =
-        CommonAPI.post(insert(:user), %{
-          status: "This is about 2hu, but private",
-          visibility: "private"
-        })
-
-      capture_log(fn ->
-        q = Object.normalize(activity, fetch: false).data["id"]
-
-        results =
-          conn
-          |> get("/api/v1/search?q=#{q}")
-          |> json_response_and_validate_schema(200)
-
-        [] = results["statuses"]
-      end)
-    end
-
-    test "search fetches remote accounts", %{conn: conn} do
-      user = insert(:user)
-
-      query = URI.encode_query(%{q: "       mike@osada.macgirvin.com          ", resolve: true})
-
-      results =
-        conn
-        |> assign(:user, user)
-        |> assign(:token, insert(:oauth_token, user: user, scopes: ["read"]))
-        |> get("/api/v1/search?#{query}")
-        |> json_response_and_validate_schema(200)
-
-      [account] = results["accounts"]
-      assert account["acct"] == "mike@osada.macgirvin.com"
-    end
-
-    test "search doesn't fetch remote accounts if resolve is false", %{conn: conn} do
-      results =
-        conn
-        |> get("/api/v1/search?q=mike@osada.macgirvin.com&resolve=false")
-        |> json_response_and_validate_schema(200)
-
-      assert [] == results["accounts"]
-    end
-
-    test "search with limit and offset", %{conn: conn} do
-      user = insert(:user)
-      _user_two = insert(:user, %{nickname: "shp@shitposter.club"})
-      _user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
-
-      {:ok, _activity1} = CommonAPI.post(user, %{status: "This is about 2hu"})
-      {:ok, _activity2} = CommonAPI.post(user, %{status: "This is also about 2hu"})
-
-      result =
-        conn
-        |> get("/api/v1/search?q=2hu&limit=1")
-
-      assert results = json_response_and_validate_schema(result, 200)
-      assert [%{"id" => activity_id1}] = results["statuses"]
-      assert [_] = results["accounts"]
-
-      results =
-        conn
-        |> get("/api/v1/search?q=2hu&limit=1&offset=1")
-        |> json_response_and_validate_schema(200)
-
-      assert [%{"id" => activity_id2}] = results["statuses"]
-      assert [] = results["accounts"]
-
-      assert activity_id1 != activity_id2
-    end
-
-    test "search returns results only for the given type", %{conn: conn} do
-      user = insert(:user)
-      _user_two = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
-
-      {:ok, _activity} = CommonAPI.post(user, %{status: "This is about 2hu"})
-
-      assert %{"statuses" => [_activity], "accounts" => [], "hashtags" => []} =
-               conn
-               |> get("/api/v1/search?q=2hu&type=statuses")
-               |> json_response_and_validate_schema(200)
-
-      assert %{"statuses" => [], "accounts" => [_user_two], "hashtags" => []} =
-               conn
-               |> get("/api/v1/search?q=2hu&type=accounts")
-               |> json_response_and_validate_schema(200)
-    end
-
-    test "search uses account_id to filter statuses by the author", %{conn: conn} do
-      user = insert(:user, %{nickname: "shp@shitposter.club"})
-      user_two = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
-
-      {:ok, activity1} = CommonAPI.post(user, %{status: "This is about 2hu"})
-      {:ok, activity2} = CommonAPI.post(user_two, %{status: "This is also about 2hu"})
-
-      results =
-        conn
-        |> get("/api/v1/search?q=2hu&account_id=#{user.id}")
-        |> json_response_and_validate_schema(200)
-
-      assert [%{"id" => activity_id1}] = results["statuses"]
-      assert activity_id1 == activity1.id
-      assert [_] = results["accounts"]
-
-      results =
-        conn
-        |> get("/api/v1/search?q=2hu&account_id=#{user_two.id}")
-        |> json_response_and_validate_schema(200)
-
-      assert [%{"id" => activity_id2}] = results["statuses"]
-      assert activity_id2 == activity2.id
-    end
-  end
 end
index c5d20435815a0d8b632eb4c6403f4170e0b2e326..c9f3f66beaf2a77e7a4b959843ce82c1edd3a9eb 100644 (file)
@@ -1349,87 +1349,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
     end
   end
 
-  describe "cards" do
-    setup do
-      clear_config([:rich_media, :enabled], true)
-
-      oauth_access(["read:statuses"])
-    end
-
-    test "returns rich-media card", %{conn: conn, user: user} do
-      Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
-      {:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp"})
-
-      card_data = %{
-        "image" => "http://ia.media-imdb.com/images/rock.jpg",
-        "provider_name" => "example.com",
-        "provider_url" => "https://example.com",
-        "title" => "The Rock",
-        "type" => "link",
-        "url" => "https://example.com/ogp",
-        "description" =>
-          "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
-        "pleroma" => %{
-          "opengraph" => %{
-            "image" => "http://ia.media-imdb.com/images/rock.jpg",
-            "title" => "The Rock",
-            "type" => "video.movie",
-            "url" => "https://example.com/ogp",
-            "description" =>
-              "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
-          }
-        }
-      }
-
-      response =
-        conn
-        |> get("/api/v1/statuses/#{activity.id}/card")
-        |> json_response_and_validate_schema(200)
-
-      assert response == card_data
-
-      # works with private posts
-      {:ok, activity} =
-        CommonAPI.post(user, %{status: "https://example.com/ogp", visibility: "direct"})
-
-      response_two =
-        conn
-        |> get("/api/v1/statuses/#{activity.id}/card")
-        |> json_response_and_validate_schema(200)
-
-      assert response_two == card_data
-    end
-
-    test "replaces missing description with an empty string", %{conn: conn, user: user} do
-      Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
-      {:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp-missing-data"})
-
-      response =
-        conn
-        |> get("/api/v1/statuses/#{activity.id}/card")
-        |> json_response_and_validate_schema(:ok)
-
-      assert response == %{
-               "type" => "link",
-               "title" => "Pleroma",
-               "description" => "",
-               "image" => nil,
-               "provider_name" => "example.com",
-               "provider_url" => "https://example.com",
-               "url" => "https://example.com/ogp-missing-data",
-               "pleroma" => %{
-                 "opengraph" => %{
-                   "title" => "Pleroma",
-                   "type" => "website",
-                   "url" => "https://example.com/ogp-missing-data"
-                 }
-               }
-             }
-    end
-  end
-
   test "bookmarks" do
     bookmarks_uri = "/api/v1/bookmarks"
 
index a817a2dba181276dd62391e691968d4a3e463024..1114da242aad153c53d708a102a82b6fdabfaae6 100644 (file)
@@ -307,165 +307,147 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
     end
   end
 
-  for tested_endpoint <- ["/api/v1/pleroma/chats", "/api/v2/pleroma/chats"] do
-    describe "GET #{tested_endpoint}" do
-      setup do: oauth_access(["read:chats"])
+  describe "GET /api/v2/pleroma/chats" do
+    setup do: oauth_access(["read:chats"])
+
+    test "it does not return chats with deleted users", %{conn: conn, user: user} do
+      recipient = insert(:user)
+      {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+
+      Pleroma.Repo.delete(recipient)
+      User.invalidate_cache(recipient)
+
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 0
+    end
+
+    test "it does not return chats with users you blocked", %{conn: conn, user: user} do
+      recipient = insert(:user)
+
+      {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 1
+
+      User.block(user, recipient)
+
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 0
+    end
+
+    test "it does not return chats with users you muted", %{conn: conn, user: user} do
+      recipient = insert(:user)
+
+      {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 1
+
+      User.mute(user, recipient)
+
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 0
+
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats?with_muted=true")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 1
+    end
 
-      test "it does not return chats with deleted users", %{conn: conn, user: user} do
+    test "it paginates chats", %{conn: conn, user: user} do
+      Enum.each(1..30, fn _ ->
         recipient = insert(:user)
         {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+      end)
 
-        Pleroma.Repo.delete(recipient)
-        User.invalidate_cache(recipient)
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats")
+        |> json_response_and_validate_schema(200)
+
+      assert length(result) == 20
+      last_id = List.last(result)["id"]
+
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats?max_id=#{last_id}")
+        |> json_response_and_validate_schema(200)
 
-        result =
-          conn
-          |> get(unquote(tested_endpoint))
-          |> json_response_and_validate_schema(200)
+      assert length(result) == 10
+    end
 
-        assert length(result) == 0
-      end
+    test "it return a list of chats the current user is participating in, in descending order of updates",
+         %{conn: conn, user: user} do
+      har = insert(:user)
+      jafnhar = insert(:user)
+      tridi = insert(:user)
 
-      test "it does not return chats with users you blocked", %{conn: conn, user: user} do
-        recipient = insert(:user)
+      {:ok, chat_1} = Chat.get_or_create(user.id, har.ap_id)
+      {:ok, chat_1} = time_travel(chat_1, -3)
+      {:ok, chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id)
+      {:ok, _chat_2} = time_travel(chat_2, -2)
+      {:ok, chat_3} = Chat.get_or_create(user.id, tridi.ap_id)
+      {:ok, chat_3} = time_travel(chat_3, -1)
 
-        {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+      # bump the second one
+      {:ok, chat_2} = Chat.bump_or_create(user.id, jafnhar.ap_id)
 
-        result =
-          conn
-          |> get(unquote(tested_endpoint))
-          |> json_response_and_validate_schema(200)
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats")
+        |> json_response_and_validate_schema(200)
 
-        assert length(result) == 1
+      ids = Enum.map(result, & &1["id"])
 
-        User.block(user, recipient)
+      assert ids == [
+               chat_2.id |> to_string(),
+               chat_3.id |> to_string(),
+               chat_1.id |> to_string()
+             ]
+    end
 
-        result =
-          conn
-          |> get(unquote(tested_endpoint))
-          |> json_response_and_validate_schema(200)
+    test "it is not affected by :restrict_unauthenticated setting (issue #1973)", %{
+      conn: conn,
+      user: user
+    } do
+      clear_config([:restrict_unauthenticated, :profiles, :local], true)
+      clear_config([:restrict_unauthenticated, :profiles, :remote], true)
 
-        assert length(result) == 0
-      end
+      user2 = insert(:user)
+      user3 = insert(:user, local: false)
 
-      test "it does not return chats with users you muted", %{conn: conn, user: user} do
-        recipient = insert(:user)
+      {:ok, _chat_12} = Chat.get_or_create(user.id, user2.ap_id)
+      {:ok, _chat_13} = Chat.get_or_create(user.id, user3.ap_id)
 
-        {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
+      result =
+        conn
+        |> get("/api/v2/pleroma/chats")
+        |> json_response_and_validate_schema(200)
 
-        result =
-          conn
-          |> get(unquote(tested_endpoint))
-          |> json_response_and_validate_schema(200)
-
-        assert length(result) == 1
-
-        User.mute(user, recipient)
-
-        result =
-          conn
-          |> get(unquote(tested_endpoint))
-          |> json_response_and_validate_schema(200)
-
-        assert length(result) == 0
-
-        result =
-          conn
-          |> get("#{unquote(tested_endpoint)}?with_muted=true")
-          |> json_response_and_validate_schema(200)
-
-        assert length(result) == 1
-      end
-
-      if tested_endpoint == "/api/v1/pleroma/chats" do
-        test "it returns all chats", %{conn: conn, user: user} do
-          Enum.each(1..30, fn _ ->
-            recipient = insert(:user)
-            {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
-          end)
-
-          result =
-            conn
-            |> get(unquote(tested_endpoint))
-            |> json_response_and_validate_schema(200)
-
-          assert length(result) == 30
-        end
-      else
-        test "it paginates chats", %{conn: conn, user: user} do
-          Enum.each(1..30, fn _ ->
-            recipient = insert(:user)
-            {:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
-          end)
-
-          result =
-            conn
-            |> get(unquote(tested_endpoint))
-            |> json_response_and_validate_schema(200)
-
-          assert length(result) == 20
-          last_id = List.last(result)["id"]
-
-          result =
-            conn
-            |> get(unquote(tested_endpoint) <> "?max_id=#{last_id}")
-            |> json_response_and_validate_schema(200)
-
-          assert length(result) == 10
-        end
-      end
-
-      test "it return a list of chats the current user is participating in, in descending order of updates",
-           %{conn: conn, user: user} do
-        har = insert(:user)
-        jafnhar = insert(:user)
-        tridi = insert(:user)
-
-        {:ok, chat_1} = Chat.get_or_create(user.id, har.ap_id)
-        {:ok, chat_1} = time_travel(chat_1, -3)
-        {:ok, chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id)
-        {:ok, _chat_2} = time_travel(chat_2, -2)
-        {:ok, chat_3} = Chat.get_or_create(user.id, tridi.ap_id)
-        {:ok, chat_3} = time_travel(chat_3, -1)
-
-        # bump the second one
-        {:ok, chat_2} = Chat.bump_or_create(user.id, jafnhar.ap_id)
-
-        result =
-          conn
-          |> get(unquote(tested_endpoint))
-          |> json_response_and_validate_schema(200)
-
-        ids = Enum.map(result, & &1["id"])
-
-        assert ids == [
-                 chat_2.id |> to_string(),
-                 chat_3.id |> to_string(),
-                 chat_1.id |> to_string()
-               ]
-      end
-
-      test "it is not affected by :restrict_unauthenticated setting (issue #1973)", %{
-        conn: conn,
-        user: user
-      } do
-        clear_config([:restrict_unauthenticated, :profiles, :local], true)
-        clear_config([:restrict_unauthenticated, :profiles, :remote], true)
-
-        user2 = insert(:user)
-        user3 = insert(:user, local: false)
-
-        {:ok, _chat_12} = Chat.get_or_create(user.id, user2.ap_id)
-        {:ok, _chat_13} = Chat.get_or_create(user.id, user3.ap_id)
-
-        result =
-          conn
-          |> get(unquote(tested_endpoint))
-          |> json_response_and_validate_schema(200)
-
-        account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
-        assert Enum.sort(account_ids) == Enum.sort([user2.id, user3.id])
-      end
+      account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
+      assert Enum.sort(account_ids) == Enum.sort([user2.id, user3.id])
     end
   end
 end
index 34f1505d0e5adf41446a546ddfb45987fb13e3cd..01eb4ad7fba1e46278bdbdb353b8781f541e2a5b 100644 (file)
@@ -42,7 +42,7 @@ defmodule Pleroma.Tests.Helpers do
     # Displaying a warning to prevent unintentional clearing of all but one keys in section
     if Keyword.keyword?(temp_setting) and length(temp_setting) == 1 do
       Logger.warn(
-        "Please change `clear_config([section], key: value)` to `clear_config([section, key], value)`"
+        "Please change `clear_config([section], key: value)` to `clear_config([section, key], value) (#{inspect(config_path)} = #{inspect(temp_setting)})`"
       )
     end