MastoAPI: Profile directory
[akkoma] / test / pleroma / web / mastodon_api / controllers / directory_controller_test.exs
1 defmodule Pleroma.Web.MastodonAPI.DirectoryControllerTest do
2 use Pleroma.Web.ConnCase, async: true
3 alias Pleroma.Web.CommonAPI
4 import Pleroma.Factory
5
6 test "GET /api/v1/directory with :profile_directory disabled returns empty array", %{conn: conn} do
7 clear_config([:instance, :profile_directory], false)
8
9 insert(:user, is_discoverable: true)
10 insert(:user, is_discoverable: true)
11
12 result =
13 conn
14 |> get("/api/v1/directory")
15 |> json_response_and_validate_schema(200)
16
17 assert result == []
18 end
19
20 test "GET /api/v1/directory returns discoverable users only", %{conn: conn} do
21 %{id: user_id} = insert(:user, is_discoverable: true)
22 insert(:user, is_discoverable: false)
23
24 result =
25 conn
26 |> get("/api/v1/directory")
27 |> json_response_and_validate_schema(200)
28
29 assert [%{"id" => ^user_id}] = result
30 end
31
32 test "GET /api/v1/directory returns users sorted by most recent statuses", %{conn: conn} do
33 insert(:user, is_discoverable: true)
34 %{id: user_id} = user = insert(:user, is_discoverable: true)
35 insert(:user, is_discoverable: true)
36
37 {:ok, _activity} = CommonAPI.post(user, %{status: "yay i'm discoverable"})
38
39 result =
40 conn
41 |> get("/api/v1/directory?order=active")
42 |> json_response_and_validate_schema(200)
43
44 assert [%{"id" => ^user_id} | _tail] = result
45 end
46 end