8784: Fix test for latest firefox.
[arvados.git] / apps / workbench / test / unit / arvados_resource_list_test.rb
1 require 'test_helper'
2
3 class ResourceListTest < ActiveSupport::TestCase
4
5   reset_api_fixtures :after_each_test, false
6
7   test 'links_for on a resource list that does not return links' do
8     use_token :active
9     results = Specimen.all
10     assert_equal [], results.links_for(api_fixture('users')['active']['uuid'])
11   end
12
13   test 'get all items by default' do
14     use_token :admin
15     a = 0
16     Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').each do
17       a += 1
18     end
19     assert_equal 201, a
20   end
21
22   test 'prefetch all items' do
23     use_token :admin
24     a = 0
25     Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').each do
26       a += 1
27     end
28     assert_equal 201, a
29   end
30
31   test 'get limited items' do
32     use_token :admin
33     a = 0
34     Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(51).each do
35       a += 1
36     end
37     assert_equal 51, a
38   end
39
40   test 'get limited items, limit % page_size != 0' do
41     skip "Requires server MAX_LIMIT < 200 which is not currently the default"
42
43     use_token :admin
44     max_page_size = Collection.
45       where(owner_uuid: 'zzzzz-j7d0g-0201collections').
46       limit(1000000000).
47       fetch_multiple_pages(false).
48       count
49     # Conditions necessary for this test to be valid:
50     assert_operator 200, :>, max_page_size
51     assert_operator 1, :<, max_page_size
52     # Verify that the server really sends max_page_size when asked for max_page_size+1
53     assert_equal max_page_size, Collection.
54       where(owner_uuid: 'zzzzz-j7d0g-0201collections').
55       limit(max_page_size+1).
56       fetch_multiple_pages(false).
57       results.
58       count
59     # Now that we know the max_page_size+1 is in the middle of page 2,
60     # make sure #each returns page 1 and only the requested part of
61     # page 2.
62     a = 0
63     saw_uuid = {}
64     Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').limit(max_page_size+1).each do |item|
65       a += 1
66       saw_uuid[item.uuid] = true
67     end
68     assert_equal max_page_size+1, a
69     # Ensure no overlap between pages
70     assert_equal max_page_size+1, saw_uuid.size
71   end
72
73   test 'get single page of items' do
74     use_token :admin
75     a = 0
76     c = Collection.where(owner_uuid: 'zzzzz-j7d0g-0201collections').fetch_multiple_pages(false)
77     c.each do
78       a += 1
79     end
80
81     assert_operator a, :<, 201
82     assert_equal c.result_limit, a
83   end
84
85   test 'get empty set' do
86     use_token :admin
87     c = Collection.
88       where(owner_uuid: 'doesn-texis-tdoesntexistdoe').
89       fetch_multiple_pages(false)
90     # Important: check c.result_offset before calling c.results here.
91     assert_equal 0, c.result_offset
92     assert_equal 0, c.items_available
93     assert_empty c.results
94   end
95
96   test 'count=none' do
97     use_token :active
98     c = Collection.with_count('none')
99     assert_nil c.items_available
100     refute_empty c.results
101   end
102 end