17417: Merge branch 'main' into 17417-add-arm64
[arvados.git] / services / api / test / integration / select_test.rb
index 20575654e6ac6c97cb9ef1e80f05024c3e2d7823..2ee3b3cf94cab5c73f3b4e809db8b6afac7aec81 100644 (file)
@@ -1,29 +1,50 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class SelectTest < ActionDispatch::IntegrationTest
   test "should select just two columns" do
-    get "/arvados/v1/links", {:format => :json, :select => ['uuid', 'link_class']}, auth(:active)
+    get "/arvados/v1/links",
+      params: {:format => :json, :select => ['uuid', 'link_class']},
+      headers: auth(:active)
     assert_response :success
     assert_equal json_response['items'].count, json_response['items'].select { |i|
-      i.count == 2 and i['uuid'] != nil and i['link_class'] != nil
+      i.count == 3 and i['uuid'] != nil and i['link_class'] != nil
     }.count
   end
 
   test "fewer distinct than total count" do
-    get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => false}, auth(:active)
+    get "/arvados/v1/links",
+      params: {:format => :json, :select => ['link_class']},
+      headers: auth(:active)
+    assert_response :success
+    distinct_unspecified = json_response['items']
+
+    get "/arvados/v1/links",
+      params: {:format => :json, :select => ['link_class'], :distinct => false},
+      headers: auth(:active)
     assert_response :success
-    links = json_response['items']
+    distinct_false = json_response['items']
 
-    get "/arvados/v1/links", {:format => :json, :select => ['link_class'], :distinct => true}, auth(:active)
+    get "/arvados/v1/links",
+      params: {:format => :json, :select => ['link_class'], :distinct => true},
+      headers: auth(:active)
     assert_response :success
     distinct = json_response['items']
 
-    assert distinct.count < links.count, "distinct count should be less than link count"
-    assert_equal links.uniq.count, distinct.count
+    assert_operator(distinct.count, :<, distinct_false.count,
+                    "distinct=true count should be less than distinct=false count")
+    assert_equal(distinct_unspecified.count, distinct_false.count,
+                    "distinct=false should be the default")
+    assert_equal distinct_false.uniq.count, distinct.count
   end
 
   test "select with order" do
-    get "/arvados/v1/links", {:format => :json, :select => ['uuid'], :order => ["uuid asc"]}, auth(:active)
+    get "/arvados/v1/links",
+      params: {:format => :json, :select => ['uuid'], :order => ["uuid asc"]},
+      headers: auth(:active)
     assert_response :success
 
     assert json_response['items'].length > 0
@@ -35,6 +56,15 @@ class SelectTest < ActionDispatch::IntegrationTest
     end
   end
 
+  test "select with default order" do
+    get "/arvados/v1/links",
+      params: {format: :json, select: ['uuid']},
+      headers: auth(:admin)
+    assert_response :success
+    uuids = json_response['items'].collect { |i| i['uuid'] }
+    assert_equal uuids, uuids.sort
+  end
+
   def assert_link_classes_ascend(current_class, prev_class)
     # Databases and Ruby don't always agree about string ordering with
     # punctuation.  If the strings aren't ascending normally, check
@@ -46,7 +76,12 @@ class SelectTest < ActionDispatch::IntegrationTest
   end
 
   test "select two columns with order" do
-    get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]}, auth(:active)
+    get "/arvados/v1/links",
+      params: {
+        :format => :json,
+        :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]
+      },
+      headers: auth(:active)
     assert_response :success
 
     assert json_response['items'].length > 0
@@ -68,7 +103,12 @@ class SelectTest < ActionDispatch::IntegrationTest
   end
 
   test "select two columns with old-style order syntax" do
-    get "/arvados/v1/links", {:format => :json, :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'}, auth(:active)
+    get "/arvados/v1/links",
+      params: {
+        :format => :json,
+        :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'
+      },
+      headers: auth(:active)
     assert_response :success
 
     assert json_response['items'].length > 0