Merge branch 'master' into 2752-arv-put-resume-wip
[arvados.git] / apps / workbench / test / unit / arvados_resource_list_test.rb
1 require 'test_helper'
2
3 class ResourceListTest < ActiveSupport::TestCase
4
5   test 'links_for on a resource list that does not return links' do
6     use_token :active
7     results = Specimen.all
8     assert_equal [], results.links_for(api_fixture('users')['active']['uuid'])
9   end
10
11   test 'links_for on non-empty resource list' do
12     use_token :active
13     results = Group.find(api_fixture('groups')['afolder']['uuid']).contents(include_linked: true)
14     assert_equal [], results.links_for(api_fixture('users')['active']['uuid'])
15     assert_equal [], results.links_for(api_fixture('jobs')['running_cancelled']['uuid'])
16     assert_equal [], results.links_for(api_fixture('jobs')['running']['uuid'], 'bogus-link-class')
17     assert_equal true, results.links_for(api_fixture('jobs')['running']['uuid'], 'name').any?
18   end
19
20   test 'links_for returns all link classes (simulated results)' do
21     folder_uuid = api_fixture('groups')['afolder']['uuid']
22     specimen_uuid = api_fixture('specimens')['in_afolder']['uuid']
23     api_response = {
24       kind: 'arvados#specimenList',
25       links: [{kind: 'arvados#link',
26                 uuid: 'zzzzz-o0j2j-asdfasdfasdfas0',
27                 tail_uuid: folder_uuid,
28                 head_uuid: specimen_uuid,
29                 link_class: 'name',
30                 name: 'Alice'},
31               {kind: 'arvados#link',
32                 uuid: 'zzzzz-o0j2j-asdfasdfasdfas1',
33                 tail_uuid: folder_uuid,
34                 head_uuid: specimen_uuid,
35                 link_class: 'foo',
36                 name: 'Bob'},
37               {kind: 'arvados#link',
38                 uuid: 'zzzzz-o0j2j-asdfasdfasdfas2',
39                 tail_uuid: folder_uuid,
40                 head_uuid: specimen_uuid,
41                 link_class: nil,
42                 name: 'Clydesdale'}],
43       items: [{kind: 'arvados#specimen',
44                 uuid: specimen_uuid}]
45     }
46     arl = ArvadosResourceList.new
47     arl.results = ArvadosApiClient.new.unpack_api_response(api_response)
48     assert_equal(['name', 'foo', nil],
49                  (arl.
50                   links_for(specimen_uuid).
51                   collect { |x| x.link_class }),
52                  "Expected links_for to return all link_classes")
53   end
54
55 end