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