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