8784: Fix test for latest firefox.
[arvados.git] / services / api / test / unit / workflow_test.rb
1 require 'test_helper'
2
3 class WorkflowTest < ActiveSupport::TestCase
4   test "create workflow with no definition yaml" do
5     set_user_from_auth :active
6
7     wf = {
8       name: "test name",
9     }
10
11     w = Workflow.create!(wf)
12     assert_not_nil w.uuid
13   end
14
15   test "create workflow with valid definition yaml" do
16     set_user_from_auth :active
17
18     wf = {
19       name: "test name",
20       definition: "k1:\n v1: x\n v2: y"
21     }
22
23     w = Workflow.create!(wf)
24     assert_not_nil w.uuid
25   end
26
27   test "create workflow with simple string as definition" do
28     set_user_from_auth :active
29
30     wf = {
31       name: "test name",
32       definition: "this is valid yaml"
33     }
34
35     w = Workflow.create!(wf)
36     assert_not_nil w.uuid
37   end
38
39   test "create workflow with invalid definition yaml" do
40     set_user_from_auth :active
41
42     wf = {
43       name: "test name",
44       definition: "k1:\n v1: x\n  v2: y"
45     }
46
47     assert_raises(ActiveRecord::RecordInvalid) do
48       Workflow.create! wf
49     end
50   end
51
52   test "update workflow with invalid definition yaml" do
53     set_user_from_auth :active
54
55     w = Workflow.find_by_uuid(workflows(:workflow_with_definition_yml).uuid)
56     definition = "k1:\n v1: x\n  v2: y"
57
58     assert_raises(ActiveRecord::RecordInvalid) do
59       w.update_attributes!(definition: definition)
60     end
61   end
62
63   test "update workflow and verify name and description" do
64     set_user_from_auth :active
65
66     # Workflow name and desc should be set with values from definition yaml
67     # when it does not already have custom values for these fields
68     w = Workflow.find_by_uuid(workflows(:workflow_with_no_name_and_desc).uuid)
69     definition = "name: test name 1\ndescription: test desc 1\nother: some more"
70     w.update_attributes!(definition: definition)
71     w.reload
72     assert_equal "test name 1", w.name
73     assert_equal "test desc 1", w.description
74
75     # Workflow name and desc should be set with values from definition yaml
76     # when it does not already have custom values for these fields
77     definition = "name: test name 2\ndescription: test desc 2\nother: some more"
78     w.update_attributes!(definition: definition)
79     w.reload
80     assert_equal "test name 2", w.name
81     assert_equal "test desc 2", w.description
82
83     # Workflow name and desc should be set with values from definition yaml
84     # even if it means emptying them out
85     definition = "more: etc"
86     w.update_attributes!(definition: definition)
87     w.reload
88     assert_nil w.name
89     assert_nil w.description
90
91     # Workflow name and desc set using definition yaml should be cleared
92     # if definition yaml is cleared
93     definition = "name: test name 2\ndescription: test desc 2\nother: some more"
94     w.update_attributes!(definition: definition)
95     w.reload
96     definition = nil
97     w.update_attributes!(definition: definition)
98     w.reload
99     assert_nil w.name
100     assert_nil w.description
101
102     # Workflow name and desc should be set to provided custom values
103     definition = "name: test name 3\ndescription: test desc 3\nother: some more"
104     w.update_attributes!(name: "remains", description: "remains", definition: definition)
105     w.reload
106     assert_equal "remains", w.name
107     assert_equal "remains", w.description
108
109     # Workflow name and desc should retain provided custom values
110     # and should not be overwritten by values from yaml
111     definition = "name: test name 4\ndescription: test desc 4\nother: some more"
112     w.update_attributes!(definition: definition)
113     w.reload
114     assert_equal "remains", w.name
115     assert_equal "remains", w.description
116
117     # Workflow name and desc should retain provided custom values
118     # and not be affected by the clearing of the definition yaml
119     definition = nil
120     w.update_attributes!(definition: definition)
121     w.reload
122     assert_equal "remains", w.name
123     assert_equal "remains", w.description
124   end
125 end