Merge branch '12462-search-periods'
[arvados.git] / apps / workbench / test / controllers / disabled_api_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 require 'helpers/share_object_helper'
7
8 class DisabledApiTest < ActionController::TestCase
9   test "dashboard recent processes when pipeline_instance index API is disabled" do
10     @controller = ProjectsController.new
11
12     dd = ArvadosApiClient.new_or_current.discovery.deep_dup
13     dd[:resources][:pipeline_instances][:methods].delete(:index)
14     ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
15
16     get :index, {}, session_for(:active)
17     assert_includes @response.body, "zzzzz-xvhdp-cr4runningcntnr" # expect crs
18     assert_not_includes @response.body, "zzzzz-d1hrv-"   # expect no pipelines
19     assert_includes @response.body, "Run a process"
20   end
21
22   test "dashboard compute node status not shown when pipeline_instance index API is disabled" do
23     @controller = ProjectsController.new
24
25     dd = ArvadosApiClient.new_or_current.discovery.deep_dup
26     dd[:resources][:pipeline_instances][:methods].delete(:index)
27     ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
28
29     get :index, {}, session_for(:active)
30     assert_not_includes @response.body, "compute-node-summary-pane"
31   end
32
33   [
34     [:jobs, JobsController.new],
35     [:job_tasks, JobTasksController.new],
36     [:pipeline_instances, PipelineInstancesController.new],
37     [:pipeline_templates, PipelineTemplatesController.new],
38   ].each do |ctrl_name, ctrl|
39     test "#{ctrl_name} index page when API is disabled" do
40       @controller = ctrl
41
42       dd = ArvadosApiClient.new_or_current.discovery.deep_dup
43       dd[:resources][ctrl_name][:methods].delete(:index)
44       ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
45
46       get :index, {}, session_for(:active)
47       assert_response 404
48     end
49   end
50
51   [
52     :admin,
53     :active,
54     nil,
55   ].each do |user|
56     test "project tabs as user #{user} when pipeline related index APIs are disabled" do
57       @controller = ProjectsController.new
58
59       Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
60
61       dd = ArvadosApiClient.new_or_current.discovery.deep_dup
62       dd[:resources][:pipeline_templates][:methods].delete(:index)
63       ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
64
65       proj_uuid = api_fixture('groups')['anonymously_accessible_project']['uuid']
66
67       if user
68         get(:show, {id: proj_uuid}, session_for(user))
69       else
70         get(:show, {id: proj_uuid})
71       end
72
73       resp = @response.body
74       assert_includes resp, "href=\"#Data_collections\""
75       assert_includes resp, "href=\"#Pipelines_and_processes\""
76       assert_includes resp, "href=\"#Workflows\""
77       assert_not_includes resp, "href=\"#Pipeline_templates\""
78       assert_includes @response.body, "Run a process" if user == :admin
79     end
80   end
81 end