3782: code review feedback
[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 returns all link classes (simulated results)' do
12     project_uuid = api_fixture('groups')['aproject']['uuid']
13     specimen_uuid = api_fixture('specimens')['in_aproject']['uuid']
14     api_response = {
15       kind: 'arvados#specimenList',
16       links: [{kind: 'arvados#link',
17                 uuid: 'zzzzz-o0j2j-asdfasdfasdfas1',
18                 tail_uuid: project_uuid,
19                 head_uuid: specimen_uuid,
20                 link_class: 'foo',
21                 name: 'Bob'},
22               {kind: 'arvados#link',
23                 uuid: 'zzzzz-o0j2j-asdfasdfasdfas2',
24                 tail_uuid: project_uuid,
25                 head_uuid: specimen_uuid,
26                 link_class: nil,
27                 name: 'Clydesdale'}],
28       items: [{kind: 'arvados#specimen',
29                 uuid: specimen_uuid}]
30     }
31     arl = ArvadosResourceList.new
32     arl.results = ArvadosApiClient.new.unpack_api_response(api_response)
33     assert_equal(['foo', nil],
34                  (arl.
35                   links_for(specimen_uuid).
36                   collect { |x| x.link_class }),
37                  "Expected links_for to return all link_classes")
38   end
39
40 end