1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class SelectTest < ActionDispatch::IntegrationTest
8 test "should select just two columns" do
9 get "/arvados/v1/links",
10 params: {:format => :json, :select => ['uuid', 'link_class']},
11 headers: auth(:active)
12 assert_response :success
13 assert_equal json_response['items'].count, json_response['items'].select { |i|
14 i.count == 3 and i['uuid'] != nil and i['link_class'] != nil
18 test "fewer distinct than total count" do
19 get "/arvados/v1/links",
20 params: {:format => :json, :select => ['link_class'], :distinct => false},
21 headers: auth(:active)
22 assert_response :success
23 links = json_response['items']
25 get "/arvados/v1/links",
26 params: {:format => :json, :select => ['link_class'], :distinct => true},
27 headers: auth(:active)
28 assert_response :success
29 distinct = json_response['items']
31 assert_operator(distinct.count, :<, links.count,
32 "distinct count should be less than link count")
33 assert_equal links.uniq.count, distinct.count
36 test "select with order" do
37 get "/arvados/v1/links",
38 params: {:format => :json, :select => ['uuid'], :order => ["uuid asc"]},
39 headers: auth(:active)
40 assert_response :success
42 assert json_response['items'].length > 0
45 json_response['items'].each do |i|
51 test "select with default order" do
52 get "/arvados/v1/links",
53 params: {format: :json, select: ['uuid']},
55 assert_response :success
56 uuids = json_response['items'].collect { |i| i['uuid'] }
57 assert_equal uuids, uuids.sort
60 def assert_link_classes_ascend(current_class, prev_class)
61 # Databases and Ruby don't always agree about string ordering with
62 # punctuation. If the strings aren't ascending normally, check
63 # that they're equal up to punctuation.
64 if current_class < prev_class
65 class_prefix = current_class.split(/\W/).first
66 assert prev_class.start_with?(class_prefix)
70 test "select two columns with order" do
71 get "/arvados/v1/links",
74 :select => ['link_class', 'uuid'], :order => ['link_class asc', "uuid desc"]
76 headers: auth(:active)
77 assert_response :success
79 assert json_response['items'].length > 0
82 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
84 json_response['items'].each do |i|
85 if prev_link_class != i['link_class']
86 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
89 assert_link_classes_ascend(i['link_class'], prev_link_class)
90 assert i['uuid'] < prev_uuid
92 prev_link_class = i['link_class']
97 test "select two columns with old-style order syntax" do
98 get "/arvados/v1/links",
101 :select => ['link_class', 'uuid'], :order => 'link_class asc, uuid desc'
103 headers: auth(:active)
104 assert_response :success
106 assert json_response['items'].length > 0
109 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
111 json_response['items'].each do |i|
112 if prev_link_class != i['link_class']
113 prev_uuid = "zzzzz-zzzzz-zzzzzzzzzzzzzzz"
116 assert_link_classes_ascend(i['link_class'], prev_link_class)
117 assert i['uuid'] < prev_uuid
119 prev_link_class = i['link_class']
120 prev_uuid = i['uuid']