3782: Remove obsolete helper method.
[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     # create 'two_part' pipeline with the given instance attributes
6     pt_fixture = api_fixture('pipeline_templates')['two_part']
7     post :create, {
8       pipeline_instance: instance_attrs.merge({
9         pipeline_template_uuid: pt_fixture['uuid']
10       }),
11       format: :json
12     }, session_for(:active)
13     assert_response :success
14     pi_uuid = assigns(:object).uuid
15     assert_not_nil assigns(:object)
16
17     # yield
18     yield pi_uuid, pt_fixture
19
20     # delete the pipeline instance
21     use_token :active
22     PipelineInstance.where(uuid: pi_uuid).first.destroy
23   end
24
25   test "pipeline instance components populated after create" do
26     create_instance_long_enough_to do |new_instance_uuid, template_fixture|
27       assert_equal(template_fixture['components'].to_json,
28                    assigns(:object).components.to_json)
29     end
30   end
31
32   test "can render pipeline instance with tagged collections" do
33     # Make sure to pass in a tagged collection to test that part of the rendering behavior.
34     get(:show,
35         {id: api_fixture("pipeline_instances")["pipeline_with_tagged_collection_input"]["uuid"]},
36         session_for(:active))
37     assert_response :success
38   end
39
40   test "update script_parameters one at a time using merge param" do
41       template_fixture = api_fixture('pipeline_templates')['two_part']
42       post :update, {
43         id: api_fixture("pipeline_instances")["pipeline_to_merge_params"]["uuid"],
44         pipeline_instance: {
45           components: {
46             "part-two" => {
47               script_parameters: {
48                 integer_with_value: {
49                   value: 9
50                 },
51                 plain_string: {
52                   value: 'quux'
53                 },
54               }
55             }
56           }
57         },
58         merge: true,
59         format: :json
60       }, session_for(:active)
61       assert_response :success
62       assert_not_nil assigns(:object)
63       orig_params = template_fixture['components']['part-two']['script_parameters']
64       new_params = assigns(:object).components[:'part-two'][:script_parameters]
65       orig_params.keys.each do |k|
66         unless %w(integer_with_value plain_string).index(k)
67           assert_equal orig_params[k].to_json, new_params[k.to_sym].to_json
68         end
69       end
70   end
71
72   test "component rendering copes with unexpeceted components format" do
73     get(:show,
74         {id: api_fixture("pipeline_instances")["components_is_jobspec"]["uuid"]},
75         session_for(:active))
76     assert_response :success
77   end
78
79   test "dates in JSON components are parsed" do
80     get(:show,
81         {id: api_fixture('pipeline_instances')['has_component_with_completed_jobs']['uuid']},
82         session_for(:active))
83     assert_response :success
84     assert_not_nil assigns(:object)
85     assert_not_nil assigns(:object).components[:foo][:job]
86     assert assigns(:object).components[:foo][:job][:started_at].is_a? Time
87     assert assigns(:object).components[:foo][:job][:finished_at].is_a? Time
88   end
89 end