Merge remote-tracking branch 'pleroma/develop' into admin-api-users-sort
authorAlex Gleason <alex@alexgleason.me>
Wed, 14 Jul 2021 03:47:47 +0000 (22:47 -0500)
committerAlex Gleason <alex@alexgleason.me>
Wed, 14 Jul 2021 03:47:47 +0000 (22:47 -0500)
1  2 
lib/pleroma/web/admin_api/search.ex
test/pleroma/web/admin_api/controllers/user_controller_test.exs

Simple merge
index 5ae2c91804751f98da1321a8a03f397de5dbaeec,1a3aa439b687a08898d2c6ae5332ee748e84df6c..3cee9532098da046b38b2833e0b1725010b71954
@@@ -376,24 -384,26 +384,24 @@@ defmodule Pleroma.Web.AdminAPI.UserCont
  
        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