1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class Arvados::V1::SchemaControllerTest < ActionController::TestCase
10 teardown do forget end
15 test "should get fresh discovery document" do
18 assert_response :success
19 discovery_doc = JSON.parse(@response.body)
20 assert_equal 'discovery#restDescription', discovery_doc['kind']
22 Time.now - MAX_SCHEMA_AGE.seconds < discovery_doc['generatedAt'],
23 "discovery document was generated >#{MAX_SCHEMA_AGE}s ago")
26 test "discovery document fields" do
28 assert_response :success
29 discovery_doc = JSON.parse(@response.body)
30 assert_includes discovery_doc, 'defaultTrashLifetime'
31 assert_equal discovery_doc['defaultTrashLifetime'], Rails.configuration.Collections.DefaultTrashLifetime
32 assert_match(/^[0-9a-f]+(-modified)?$/, discovery_doc['source_version'])
33 assert_match(/^[0-9a-f]+(-modified)?$/, discovery_doc['sourceVersion'])
34 assert_match(/^unknown$/, discovery_doc['packageVersion'])
35 assert_equal discovery_doc['websocketUrl'], Rails.configuration.Services.Websocket.ExternalURL.to_s
36 assert_equal discovery_doc['workbenchUrl'], Rails.configuration.Services.Workbench1.ExternalURL.to_s
37 assert_equal('zzzzz', discovery_doc['uuidPrefix'])
40 test "discovery document overrides source_version & sourceVersion with config" do
41 Rails.configuration.source_version = 'aaa888fff'
43 assert_response :success
44 discovery_doc = JSON.parse(@response.body)
45 # Key source_version will be replaced with sourceVersion
46 assert_equal 'aaa888fff', discovery_doc['source_version']
47 assert_equal 'aaa888fff', discovery_doc['sourceVersion']
50 test "discovery document overrides packageVersion with config" do
51 Rails.configuration.package_version = '1.0.0-stable'
53 assert_response :success
54 discovery_doc = JSON.parse(@response.body)
55 assert_equal '1.0.0-stable', discovery_doc['packageVersion']
58 test "empty disable_api_methods" do
60 assert_response :success
61 discovery_doc = JSON.parse(@response.body)
63 discovery_doc['resources']['jobs']['methods']['create']['httpMethod'])
66 test "non-empty disable_api_methods" do
67 Rails.configuration.API.DisabledAPIs = ConfigLoader.to_OrderedOptions(
68 {'jobs.create'=>{}, 'pipeline_instances.create'=>{}, 'pipeline_templates.create'=>{}})
70 assert_response :success
71 discovery_doc = JSON.parse(@response.body)
72 ['jobs', 'pipeline_instances', 'pipeline_templates'].each do |r|
73 refute_includes(discovery_doc['resources'][r]['methods'].keys(), 'create')
77 test "groups contents parameters" do
79 assert_response :success
81 discovery_doc = JSON.parse(@response.body)
83 group_index_params = discovery_doc['resources']['groups']['methods']['index']['parameters']
84 group_contents_params = discovery_doc['resources']['groups']['methods']['contents']['parameters']
86 assert_equal group_contents_params.keys.sort, (group_index_params.keys - ['select'] + ['uuid', 'recursive', 'include', 'include_old_versions']).sort
88 recursive_param = group_contents_params['recursive']
89 assert_equal 'boolean', recursive_param['type']
90 assert_equal false, recursive_param['required']
91 assert_equal 'query', recursive_param['location']
94 test "collections index parameters" do
96 assert_response :success
98 discovery_doc = JSON.parse(@response.body)
100 specimens_index_params = discovery_doc['resources']['specimens']['methods']['index']['parameters'] # no changes from super
101 coll_index_params = discovery_doc['resources']['collections']['methods']['index']['parameters']
103 assert_equal (specimens_index_params.keys + ['include_trash', 'include_old_versions']).sort, coll_index_params.keys.sort
105 include_trash_param = coll_index_params['include_trash']
106 assert_equal 'boolean', include_trash_param['type']
107 assert_equal false, include_trash_param['required']
108 assert_equal 'query', include_trash_param['location']