4523: update tests to include :* in the filters sent rather than expect server to...
[arvados.git] / services / api / test / integration / groups_test.rb
1 require 'test_helper'
2
3 class GroupsTest < ActionDispatch::IntegrationTest
4
5   test "get all pages of group-owned objects" do
6     limit = 5
7     offset = 0
8     items_available = nil
9     uuid_received = {}
10     owner_received = {}
11     while true
12       @json_response = nil
13
14       get "/arvados/v1/groups/contents", {
15         id: groups(:aproject).uuid,
16         limit: limit,
17         offset: offset,
18         format: :json,
19       }, auth(:active)
20
21       assert_response :success
22       assert_operator(0, :<, json_response['items'].count,
23                       "items_available=#{items_available} but received 0 "\
24                       "items with offset=#{offset}")
25       items_available ||= json_response['items_available']
26       assert_equal(items_available, json_response['items_available'],
27                    "items_available changed between page #{offset/limit} "\
28                    "and page #{1+offset/limit}")
29       json_response['items'].each do |item|
30         uuid = item['uuid']
31         assert_equal(nil, uuid_received[uuid],
32                      "Received '#{uuid}' again on page #{1+offset/limit}")
33         uuid_received[uuid] = true
34         owner_received[item['owner_uuid']] = true
35         offset += 1
36         assert_equal groups(:aproject).uuid, item['owner_uuid']
37       end
38       break if offset >= items_available
39     end
40   end
41
42   [
43     ['Collection_', true],            # collections and pipelines templates
44     ['hash', true],                   # pipeline templates
45     ['fa7aeb5140e2848d39b', false],   # script_parameter of pipeline instances
46     ['fa7aeb5140e2848d39b:*', true],  # script_parameter of pipeline instances
47     ['project pipeline', true],       # finds "Completed pipeline in A Project"
48     ['project pipeli:*', true],       # finds "Completed pipeline in A Project"
49     ['proje pipeli:*', false],        # first word is incomplete, so no prefix match
50     ['no-such-thing', false],         # script_parameter of pipeline instances
51   ].each do |search_filter, expect_results|
52     test "full text search of group-owned objects for #{search_filter}" do
53       get "/arvados/v1/groups/contents", {
54         id: groups(:aproject).uuid,
55         limit: 5,
56         :filters => [['any', '@@', search_filter]].to_json
57       }, auth(:active)
58       assert_response :success
59       if expect_results
60         refute_empty json_response['items']
61         json_response['items'].each do |item|
62           assert item['uuid']
63           assert_equal groups(:aproject).uuid, item['owner_uuid']
64         end
65       else
66         assert_empty json_response['items']
67       end
68     end
69   end
70
71   test "full text search is not supported for individual columns" do
72     get "/arvados/v1/groups/contents", {
73       :filters => [['name', '@@', 'Private']].to_json
74     }, auth(:active)
75     assert_response 422
76   end
77 end