Merge branch '2798-go-keep-client' into 1885-keep-proxy refs #1885
[arvados.git] / apps / workbench / test / functional / pipeline_instances_controller_test.rb
1 require 'test_helper'
2
3 class PipelineInstancesControllerTest < ActionController::TestCase
4   def create_instance_long_enough_to(instance_attrs={})
5     pt_fixture = api_fixture('pipeline_templates')['two_part']
6     post :create, {
7       pipeline_instance: instance_attrs.merge({
8         pipeline_template_uuid: pt_fixture['uuid']
9       }),
10       format: :json
11     }, session_for(:active)
12     assert_response :success
13     pi_uuid = assigns(:object).uuid
14     assert_not_nil assigns(:object)
15     yield pi_uuid, pt_fixture
16     post :destroy, {
17       id: pi_uuid,
18       format: :json
19     }
20     assert_response :success
21   end
22
23   test "pipeline instance components populated after create" do
24     create_instance_long_enough_to do |new_instance_uuid, template_fixture|
25       assert_equal(template_fixture['components'].to_json,
26                    assigns(:object).components.to_json)
27     end
28   end
29
30   test "can render pipeline instance with tagged collections" do
31     # Make sure to pass in a tagged collection to test that part of the
32     # rendering behavior.
33     attrs = {components: {'part-one' => {script_parameters: {input:
34             {value: api_fixture('collections')['foo_file']['uuid']}
35             }}}}
36     create_instance_long_enough_to(attrs) do |new_instance_uuid, template_fixture|
37       get(:show, {id: new_instance_uuid}, session_for(:active))
38       assert_response :success
39     end
40   end
41
42   test "update script_parameters one at a time using merge param" do
43     create_instance_long_enough_to do |new_instance_uuid, template_fixture|
44       post :update, {
45         id: new_instance_uuid,
46         pipeline_instance: {
47           components: {
48             "part-two" => {
49               script_parameters: {
50                 integer_with_value: {
51                   value: 9
52                 },
53                 plain_string: {
54                   value: 'quux'
55                 },
56               }
57             }
58           }
59         },
60         merge: true,
61         format: :json
62       }, session_for(:active)
63       assert_response :success
64       assert_not_nil assigns(:object)
65       orig_params = template_fixture['components']['part-two']['script_parameters']
66       new_params = assigns(:object).components[:'part-two'][:script_parameters]
67       orig_params.keys.each do |k|
68         unless %w(integer_with_value plain_string).index(k)
69           assert_equal orig_params[k].to_json, new_params[k.to_sym].to_json
70         end
71       end
72     end
73   end
74 end