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
12 Rails.cache.delete 'arvados_v1_rest_discovery'
16 test "should get fresh discovery document" do
19 assert_response :success
20 discovery_doc = JSON.parse(@response.body)
21 assert_equal 'discovery#restDescription', discovery_doc['kind']
23 Time.now - MAX_SCHEMA_AGE.seconds < discovery_doc['generatedAt'],
24 "discovery document was generated >#{MAX_SCHEMA_AGE}s ago")
27 test "discovery document fields" do
29 assert_response :success
30 discovery_doc = JSON.parse(@response.body)
31 assert_includes discovery_doc, 'defaultTrashLifetime'
32 assert_equal discovery_doc['defaultTrashLifetime'], Rails.application.config.default_trash_lifetime
33 assert_match(/^[0-9a-f]+(-modified)?$/, discovery_doc['source_version'])
34 assert_match(/^[0-9a-f]+(-modified)?$/, discovery_doc['sourceVersion'])
35 assert_match(/^unknown$/, discovery_doc['packageVersion'])
36 assert_equal discovery_doc['websocketUrl'], Rails.application.config.websocket_address
37 assert_equal discovery_doc['workbenchUrl'], Rails.application.config.workbench_address
38 assert_equal('zzzzz', discovery_doc['uuidPrefix'])
41 test "discovery document overrides source_version & sourceVersion with config" do
42 Rails.configuration.source_version = 'aaa888fff'
44 assert_response :success
45 discovery_doc = JSON.parse(@response.body)
46 # Key source_version will be replaced with sourceVersion
47 assert_equal 'aaa888fff', discovery_doc['source_version']
48 assert_equal 'aaa888fff', discovery_doc['sourceVersion']
51 test "discovery document overrides packageVersion with config" do
52 Rails.configuration.package_version = '1.0.0-stable'
54 assert_response :success
55 discovery_doc = JSON.parse(@response.body)
56 assert_equal '1.0.0-stable', discovery_doc['packageVersion']
59 test "empty disable_api_methods" do
61 assert_response :success
62 discovery_doc = JSON.parse(@response.body)
64 discovery_doc['resources']['jobs']['methods']['create']['httpMethod'])
67 test "non-empty disable_api_methods" do
68 Rails.configuration.disable_api_methods =
69 ['jobs.create', 'pipeline_instances.create', 'pipeline_templates.create']
71 assert_response :success
72 discovery_doc = JSON.parse(@response.body)
73 ['jobs', 'pipeline_instances', 'pipeline_templates'].each do |r|
74 refute_includes(discovery_doc['resources'][r]['methods'].keys(), 'create')
78 test "groups contents parameters" do
80 assert_response :success
82 discovery_doc = JSON.parse(@response.body)
84 group_index_params = discovery_doc['resources']['groups']['methods']['index']['parameters']
85 group_contents_params = discovery_doc['resources']['groups']['methods']['contents']['parameters']
87 assert_equal group_contents_params.keys.sort, (group_index_params.keys - ['select'] + ['uuid', 'recursive']).sort
89 recursive_param = group_contents_params['recursive']
90 assert_equal 'boolean', recursive_param['type']
91 assert_equal false, recursive_param['required']
92 assert_equal 'query', recursive_param['location']
95 test "collections index parameters" do
97 assert_response :success
99 discovery_doc = JSON.parse(@response.body)
101 specimens_index_params = discovery_doc['resources']['specimens']['methods']['index']['parameters'] # no changes from super
102 coll_index_params = discovery_doc['resources']['collections']['methods']['index']['parameters']
104 assert_equal (specimens_index_params.keys + ['include_trash', 'include_old_versions']).sort, coll_index_params.keys.sort
106 include_trash_param = coll_index_params['include_trash']
107 assert_equal 'boolean', include_trash_param['type']
108 assert_equal false, include_trash_param['required']
109 assert_equal 'query', include_trash_param['location']