f37b9860b52faa3a98008bad888ff4a11a8711fd
[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', true],   # script_parameter of pipeline instances
46     ['no-such-thing', false],        # script_parameter of pipeline instances
47   ].each do |search_filter, expect_results|
48     test "full text search of group-owned objects for #{search_filter}" do
49       get "/arvados/v1/groups/contents", {
50         id: groups(:aproject).uuid,
51         limit: 5,
52         :filters => [['any', '@@', search_filter]].to_json
53       }, auth(:active)
54       assert_response :success
55       if expect_results
56         assert_operator(0, :<, json_response['items'].count,
57                         "expected results but received 0")
58         json_response['items'].each do |item|
59           assert item['uuid']
60           assert_equal groups(:aproject).uuid, item['owner_uuid']
61         end
62       else
63         assert_operator(0, :==, json_response['items'].count,
64                         "expected no results but received #{json_response['items'].length}")
65       end
66     end
67   end
68
69 end