e2f5c7d81a33f9d7f32d76809e17efb9416895ad
[akkoma] / test / pleroma / user / query_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.User.QueryTest do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.Repo
9 alias Pleroma.User
10 alias Pleroma.User.Query
11 alias Pleroma.Web.ActivityPub.InternalFetchActor
12
13 import Pleroma.Factory
14
15 describe "internal users" do
16 test "it filters out internal users by default" do
17 %User{nickname: "internal.fetch"} = InternalFetchActor.get_actor()
18
19 assert [_user] = User |> Repo.all()
20 assert [] == %{} |> Query.build() |> Repo.all()
21 end
22
23 test "it filters out users without nickname by default" do
24 insert(:user, %{nickname: nil})
25
26 assert [_user] = User |> Repo.all()
27 assert [] == %{} |> Query.build() |> Repo.all()
28 end
29
30 test "it returns internal users when enabled" do
31 %User{nickname: "internal.fetch"} = InternalFetchActor.get_actor()
32 insert(:user, %{nickname: nil})
33
34 assert %{internal: true} |> Query.build() |> Repo.aggregate(:count) == 2
35 end
36 end
37 end