Merge branch '8784-dir-listings'
[arvados.git] / services / api / test / integration / groups_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class GroupsTest < ActionDispatch::IntegrationTest
8   [[], ['replication_confirmed']].each do |orders|
9     test "results are consistent when provided orders #{orders} is incomplete" do
10       last = nil
11       (0..20).each do
12         get '/arvados/v1/groups/contents', {
13           id: groups(:aproject).uuid,
14           filters: [["uuid", "is_a", "arvados#collection"]].to_json,
15           orders: orders.to_json,
16           format: :json,
17         }, auth(:active)
18         assert_response :success
19         if last.nil?
20           last = json_response['items']
21         else
22           assert_equal last, json_response['items']
23         end
24       end
25     end
26   end
27
28   test "get all pages of group-owned objects" do
29     limit = 5
30     offset = 0
31     items_available = nil
32     uuid_received = {}
33     owner_received = {}
34     while true
35       get "/arvados/v1/groups/contents", {
36         id: groups(:aproject).uuid,
37         limit: limit,
38         offset: offset,
39         format: :json,
40       }, auth(:active)
41
42       assert_response :success
43       assert_operator(0, :<, json_response['items'].count,
44                       "items_available=#{items_available} but received 0 "\
45                       "items with offset=#{offset}")
46       items_available ||= json_response['items_available']
47       assert_equal(items_available, json_response['items_available'],
48                    "items_available changed between page #{offset/limit} "\
49                    "and page #{1+offset/limit}")
50       json_response['items'].each do |item|
51         uuid = item['uuid']
52         assert_equal(nil, uuid_received[uuid],
53                      "Received '#{uuid}' again on page #{1+offset/limit}")
54         uuid_received[uuid] = true
55         owner_received[item['owner_uuid']] = true
56         offset += 1
57         assert_equal groups(:aproject).uuid, item['owner_uuid']
58       end
59       break if offset >= items_available
60     end
61   end
62
63   [
64     ['Collection_', true],            # collections and pipelines templates
65     ['hash', true],                   # pipeline templates
66     ['fa7aeb5140e2848d39b', false],   # script_parameter of pipeline instances
67     ['fa7aeb5140e2848d39b:*', true],  # script_parameter of pipeline instances
68     ['project pipeline', true],       # finds "Completed pipeline in A Project"
69     ['project pipeli:*', true],       # finds "Completed pipeline in A Project"
70     ['proje pipeli:*', false],        # first word is incomplete, so no prefix match
71     ['no-such-thing', false],         # script_parameter of pipeline instances
72   ].each do |search_filter, expect_results|
73     test "full text search of group-owned objects for #{search_filter}" do
74       get "/arvados/v1/groups/contents", {
75         id: groups(:aproject).uuid,
76         limit: 5,
77         :filters => [['any', '@@', search_filter]].to_json
78       }, auth(:active)
79       assert_response :success
80       if expect_results
81         refute_empty json_response['items']
82         json_response['items'].each do |item|
83           assert item['uuid']
84           assert_equal groups(:aproject).uuid, item['owner_uuid']
85         end
86       else
87         assert_empty json_response['items']
88       end
89     end
90   end
91
92   test "full text search is not supported for individual columns" do
93     get "/arvados/v1/groups/contents", {
94       :filters => [['name', '@@', 'Private']].to_json
95     }, auth(:active)
96     assert_response 422
97   end
98
99   test "group contents with include trash collections" do
100     get "/arvados/v1/groups/contents", {
101       include_trash: "true",
102       filters: [["uuid", "is_a", "arvados#collection"]].to_json
103     }, auth(:active)
104     assert_response 200
105
106     coll_uuids = []
107     json_response['items'].each { |c| coll_uuids << c['uuid'] }
108     assert_includes coll_uuids, collections(:foo_collection_in_aproject).uuid
109     assert_includes coll_uuids, collections(:expired_collection).uuid
110   end
111 end