closes #10524
[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     assert_not_includes @response.body, "Run a pipeline"
17   end
18
19   [
20     [:jobs, JobsController.new],
21     [:job_tasks, JobTasksController.new],
22     [:pipeline_instances, PipelineInstancesController.new],
23     [:pipeline_templates, PipelineTemplatesController.new],
24   ].each do |ctrl_name, ctrl|
25     test "#{ctrl_name} index page when API is disabled" do
26       @controller = ctrl
27
28       dd = ArvadosApiClient.new_or_current.discovery.deep_dup
29       dd[:resources][ctrl_name][:methods].delete(:index)
30       ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
31
32       get :index, {}, session_for(:active)
33       assert_response 404
34     end
35   end
36
37   [
38     :active,
39     nil,
40   ].each do |user|
41     test "project tabs as user #{user} when pipeline related index APIs are disabled" do
42       @controller = ProjectsController.new
43
44       Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
45
46       dd = ArvadosApiClient.new_or_current.discovery.deep_dup
47       dd[:resources][:pipeline_templates][:methods].delete(:index)
48       ArvadosApiClient.any_instance.stubs(:discovery).returns(dd)
49
50       proj_uuid = api_fixture('groups')['anonymously_accessible_project']['uuid']
51
52       if user
53         get(:show, {id: proj_uuid}, session_for(user))
54       else
55         get(:show, {id: proj_uuid})
56       end
57
58       resp = @response.body
59       assert_includes resp, "href=\"#Data_collections\""
60       assert_includes resp, "href=\"#Pipelines_and_processes\""
61       assert_includes resp, "href=\"#Workflows\""
62       assert_not_includes resp, "href=\"#Pipeline_templates\""
63       assert_includes @response.body, "Run a process"
64       assert_not_includes @response.body, "Run a pipeline"
65     end
66   end
67 end