Merge branch '12515-configured-workbench-address'
[arvados.git] / services / api / test / functional / arvados / v1 / schema_controller_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class Arvados::V1::SchemaControllerTest < ActionController::TestCase
8
9   setup do forget end
10   teardown do forget end
11   def forget
12     Rails.cache.delete 'arvados_v1_rest_discovery'
13     AppVersion.forget
14   end
15
16   test "should get fresh discovery document" do
17     MAX_SCHEMA_AGE = 60
18     get :index
19     assert_response :success
20     discovery_doc = JSON.parse(@response.body)
21     assert_equal 'discovery#restDescription', discovery_doc['kind']
22     assert_equal(true,
23                  Time.now - MAX_SCHEMA_AGE.seconds < discovery_doc['generatedAt'],
24                  "discovery document was generated >#{MAX_SCHEMA_AGE}s ago")
25   end
26
27   test "discovery document fields" do
28     get :index
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_equal discovery_doc['websocketUrl'], Rails.application.config.websocket_address
35     assert_equal discovery_doc['workbenchUrl'], Rails.application.config.workbench_address
36   end
37
38   test "discovery document overrides source_version with config" do
39     Rails.configuration.source_version = 'aaa888fff'
40     get :index
41     assert_response :success
42     discovery_doc = JSON.parse(@response.body)
43     assert_equal 'aaa888fff', discovery_doc['source_version']
44   end
45
46   test "empty disable_api_methods" do
47     get :index
48     assert_response :success
49     discovery_doc = JSON.parse(@response.body)
50     assert_equal('POST',
51                  discovery_doc['resources']['jobs']['methods']['create']['httpMethod'])
52   end
53
54   test "non-empty disable_api_methods" do
55     Rails.configuration.disable_api_methods =
56       ['jobs.create', 'pipeline_instances.create', 'pipeline_templates.create']
57     get :index
58     assert_response :success
59     discovery_doc = JSON.parse(@response.body)
60     ['jobs', 'pipeline_instances', 'pipeline_templates'].each do |r|
61       refute_includes(discovery_doc['resources'][r]['methods'].keys(), 'create')
62     end
63   end
64
65   test "groups contents parameters" do
66     get :index
67     assert_response :success
68
69     discovery_doc = JSON.parse(@response.body)
70
71     group_index_params = discovery_doc['resources']['groups']['methods']['index']['parameters']
72     group_contents_params = discovery_doc['resources']['groups']['methods']['contents']['parameters']
73
74     assert_equal group_contents_params.keys.sort, (group_index_params.keys - ['select'] + ['uuid', 'recursive']).sort
75
76     recursive_param = group_contents_params['recursive']
77     assert_equal 'boolean', recursive_param['type']
78     assert_equal false, recursive_param['required']
79     assert_equal 'query', recursive_param['location']
80   end
81
82   test "collections index parameters" do
83     get :index
84     assert_response :success
85
86     discovery_doc = JSON.parse(@response.body)
87
88     specimens_index_params = discovery_doc['resources']['specimens']['methods']['index']['parameters']  # no changes from super
89     coll_index_params = discovery_doc['resources']['collections']['methods']['index']['parameters']
90
91     assert_equal coll_index_params.keys.sort, (specimens_index_params.keys + ['include_trash']).sort
92
93     include_trash_param = coll_index_params['include_trash']
94     assert_equal 'boolean', include_trash_param['type']
95     assert_equal false, include_trash_param['required']
96     assert_equal 'query', include_trash_param['location']
97   end
98 end