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