X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fmastodon_api%2Fmastodon_api_controller_test.exs;h=8443dc856ba420d592f4279e083e4b05fbb3bf62;hb=707cd9389c4cebd5318fbd43527d2d3578310149;hp=fe8f845c7c0f6dde2a063cda4c76702d1bbd30aa;hpb=fa0392e49cd46e4d2845840232a4b56e52729369;p=akkoma
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index fe8f845c7..8443dc856 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -10,6 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Web.{OStatus, CommonAPI}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.MastodonAPI.FilterView
+ alias Ecto.Changeset
import Pleroma.Factory
import ExUnit.CaptureLog
import Tesla.Mock
@@ -386,7 +387,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> assign(:user, user)
|> get("/api/v1/filters/#{filter.filter_id}")
- assert response = json_response(conn, 200)
+ assert _response = json_response(conn, 200)
end
test "update a filter", %{conn: conn} do
@@ -600,7 +601,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/notifications")
expected_response =
- "hi @#{user.nickname}"
+ "hi @#{user.nickname}"
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
assert response == expected_response
@@ -621,7 +624,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("/api/v1/notifications/#{notification.id}")
expected_response =
- "hi @#{user.nickname}"
+ "hi @#{user.nickname}"
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
assert response == expected_response
@@ -1357,7 +1362,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [status] = json_response(first_conn, 200)
assert status["id"] == to_string(activity.id)
- assert [{"link", link_header}] =
+ assert [{"link", _link_header}] =
Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
# Honours query params
@@ -1402,9 +1407,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user = json_response(conn, 200)
assert user["note"] ==
- "I drink #cofe with #cofe with @#{user2.nickname}"
+ }\" class=\"u-url mention\" href=\"#{user2.ap_id}\">@#{user2.nickname}"
end
test "updates the user's locking status", %{conn: conn} do
@@ -1469,22 +1474,51 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "get instance information", %{conn: conn} do
- insert(:user, %{local: true})
user = insert(:user, %{local: true})
- insert(:user, %{local: false})
+
+ user2 = insert(:user, %{local: true})
+ {:ok, _user2} = User.deactivate(user2, !user2.info.deactivated)
+
+ insert(:user, %{local: false, nickname: "u@peer1.com"})
+ insert(:user, %{local: false, nickname: "u@peer2.com"})
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
+ # Stats should count users with missing or nil `info.deactivated` value
+ user = Repo.get(User, user.id)
+ info_change = Changeset.change(user.info, %{deactivated: nil})
+
+ {:ok, _user} =
+ user
+ |> Changeset.change()
+ |> Changeset.put_embed(:info, info_change)
+ |> User.update_and_set_cache()
+
Pleroma.Stats.update_stats()
- conn =
- conn
- |> get("/api/v1/instance")
+ conn = get(conn, "/api/v1/instance")
+
+ assert result = json_response(conn, 200)
+
+ stats = result["stats"]
+
+ assert stats
+ assert stats["user_count"] == 1
+ assert stats["status_count"] == 1
+ assert stats["domain_count"] == 2
+ end
+
+ test "get peers", %{conn: conn} do
+ insert(:user, %{local: false, nickname: "u@peer1.com"})
+ insert(:user, %{local: false, nickname: "u@peer2.com"})
+
+ Pleroma.Stats.update_stats()
+
+ conn = get(conn, "/api/v1/instance/peers")
assert result = json_response(conn, 200)
- assert result["stats"]["user_count"] == 2
- assert result["stats"]["status_count"] == 1
+ assert ["peer1.com", "peer2.com"] == Enum.sort(result)
end
test "put settings", %{conn: conn} do
@@ -1495,7 +1529,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> assign(:user, user)
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
- assert result = json_response(conn, 200)
+ assert _result = json_response(conn, 200)
user = User.get_cached_by_ap_id(user.ap_id)
assert user.info.settings == %{"programming" => "socks"}