Add test for the second page
authorMaxim Filippov <colixer@gmail.com>
Thu, 28 Feb 2019 14:54:02 +0000 (17:54 +0300)
committerMaxim Filippov <colixer@gmail.com>
Thu, 28 Feb 2019 14:54:02 +0000 (17:54 +0300)
test/web/admin_api/admin_api_controller_test.exs

index 1b0a2f5be70cb03d2356b01afdbab0868cd0a138..893387ef5425fb208cd0bdbb6ae94c361acc7d5f 100644 (file)
@@ -331,26 +331,44 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
     assert conn.status == 200
   end
 
-  test "GET /api/pleroma/admin/users" do
-    admin = insert(:user, info: %{is_admin: true})
-    user = insert(:user)
+  describe "GET /api/pleroma/admin/users" do
+    test "renders users array for the first page" do
+      admin = insert(:user, info: %{is_admin: true})
+      user = insert(:user)
 
-    conn =
-      build_conn()
-      |> assign(:user, admin)
-      |> get("/api/pleroma/admin/users?page=1")
-
-    assert json_response(conn, 200) == %{
-             "count" => 1,
-             "page_size" => 50,
-             "users" => [
-               %{
-                 "deactivated" => user.info.deactivated,
-                 "id" => user.id,
-                 "nickname" => user.nickname
-               }
-             ]
-           }
+      conn =
+        build_conn()
+        |> assign(:user, admin)
+        |> get("/api/pleroma/admin/users?page=1")
+
+      assert json_response(conn, 200) == %{
+               "count" => 1,
+               "page_size" => 50,
+               "users" => [
+                 %{
+                   "deactivated" => user.info.deactivated,
+                   "id" => user.id,
+                   "nickname" => user.nickname
+                 }
+               ]
+             }
+    end
+
+    test "renders empty array for the second page" do
+      admin = insert(:user, info: %{is_admin: true})
+      user = insert(:user)
+
+      conn =
+        build_conn()
+        |> assign(:user, admin)
+        |> get("/api/pleroma/admin/users?page=2")
+
+      assert json_response(conn, 200) == %{
+               "count" => 1,
+               "page_size" => 50,
+               "users" => []
+             }
+    end
   end
 
   test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do