conn = get(conn, "/api/pleroma/admin/users?page=1")
- users =
- [
- user_response(
- admin,
- %{"roles" => %{"admin" => true, "moderator" => false}}
- ),
- user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
- user_response(
- user2,
- %{
- "local" => true,
- "is_approved" => false,
- "registration_reason" => "I'm a chill dude",
- "actor_type" => "Person"
- }
- )
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(
+ user2,
+ %{
+ "local" => true,
+ "is_approved" => false,
+ "registration_reason" => "I'm a chill dude",
+ "actor_type" => "Person"
+ }
+ ),
+ user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
+ user_response(
+ admin,
+ %{"roles" => %{"admin" => true, "moderator" => false}}
+ )
+ ]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 3,
"page_size" => 50,
"users" => users
conn1 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=1")
- assert json_response(conn1, 200) == %{
+ assert json_response_and_validate_schema(conn1, 200) == %{
"count" => 2,
"page_size" => 1,
- "users" => [user_response(user)]
+ "users" => [user_response(user2)]
}
conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
- assert json_response(conn2, 200) == %{
+ assert json_response_and_validate_schema(conn2, 200) == %{
"count" => 2,
"page_size" => 1,
- "users" => [user_response(user2)]
+ "users" => [user_response(user)]
}
end
conn = get(conn, "/api/pleroma/admin/users?filters=local")
- users =
- [
- user_response(user),
- user_response(admin, %{
- "roles" => %{"admin" => true, "moderator" => false}
- }),
- user_response(old_admin, %{
- "is_active" => true,
- "roles" => %{"admin" => true, "moderator" => false}
- })
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(user),
+ user_response(admin, %{
+ "roles" => %{"admin" => true, "moderator" => false}
+ }),
+ user_response(old_admin, %{
+ "is_active" => true,
+ "roles" => %{"admin" => true, "moderator" => false}
+ })
+ ]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 3,
"page_size" => 50,
"users" => users
conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
- users =
- [
- user_response(admin, %{
- "is_active" => true,
- "roles" => %{"admin" => true, "moderator" => false}
- }),
- user_response(second_admin, %{
- "is_active" => true,
- "roles" => %{"admin" => true, "moderator" => false}
- })
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(second_admin, %{
+ "is_active" => true,
+ "roles" => %{"admin" => true, "moderator" => false}
+ }),
+ user_response(admin, %{
+ "is_active" => true,
+ "roles" => %{"admin" => true, "moderator" => false}
+ })
+ ]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 2,
"page_size" => 50,
"users" => users
response =
conn
- |> get(user_path(conn, :list), %{actor_types: ["Person"]})
- |> json_response(200)
+ |> get(user_path(conn, :index), %{actor_types: ["Person"]})
+ |> json_response_and_validate_schema(200)
- users =
- [
- user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
- user_response(user1),
- user_response(user2)
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(user2),
+ user_response(user1),
+ user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
+ ]
assert response == %{"count" => 3, "page_size" => 50, "users" => users}
end
response =
conn
- |> get(user_path(conn, :list), %{actor_types: ["Person", "Service"]})
- |> json_response(200)
+ |> get(user_path(conn, :index), %{actor_types: ["Person", "Service"]})
+ |> json_response_and_validate_schema(200)
- users =
- [
- user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
- user_response(user1),
- user_response(user2),
- user_response(user_service, %{"actor_type" => "Service"})
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(user2),
+ user_response(user1),
+ user_response(user_service, %{"actor_type" => "Service"}),
+ user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
+ ]
assert response == %{"count" => 4, "page_size" => 50, "users" => users}
end
conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
- users =
- [
- user_response(user1, %{"tags" => ["first"]}),
- user_response(user2, %{"tags" => ["second"]})
- ]
- |> Enum.sort_by(& &1["nickname"])
+ users = [
+ user_response(user2, %{"tags" => ["second"]}),
+ user_response(user1, %{"tags" => ["first"]})
+ ]
- assert json_response(conn, 200) == %{
+ assert json_response_and_validate_schema(conn, 200) == %{
"count" => 2,
"page_size" => 50,
"users" => users
"count" => 2,
"page_size" => 50,
"users" => [
- %{"id" => ^admin_id},
- %{"id" => ^user_id}
+ %{"id" => ^user_id},
+ %{"id" => ^admin_id}
]
- } = json_response(conn, 200)
+ } = json_response_and_validate_schema(conn, 200)
end
test "it works with multiple filters" do