Merge pull request #1 from curoverse/master
[arvados.git] / apps / workbench / test / controllers / actions_controller_test.rb
1 require 'test_helper'
2
3 class ActionsControllerTest < ActionController::TestCase
4
5   test "send report" do
6     post :report_issue, {format: 'js'}, session_for(:admin)
7     assert_response :success
8
9     found_email = false
10     ActionMailer::Base.deliveries.andand.each do |email|
11       if email.subject.include? "Issue reported by admin"
12         found_email = true
13         break
14       end
15     end
16     assert_equal true, found_email, 'Expected email after issue reported'
17   end
18
19   test "combine files into new collection" do
20     post(:combine_selected_files_into_collection, {
21            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
22                        'zzzzz-4zz18-ehbhgtheo8909or/bar',
23                        'zzzzz-4zz18-y9vne9npefyxh8g/baz',
24                        '7a6ef4c162a5c6413070a8bd0bffc818+150'],
25            format: "json"},
26          session_for(:active))
27
28     assert_response 302   # collection created and redirected to new collection page
29
30     assert response.headers['Location'].include? '/collections/'
31     new_collection_uuid = response.headers['Location'].split('/')[-1]
32
33     use_token :active
34     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
35     manifest_text = collection['manifest_text']
36     assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
37     assert manifest_text.include?('bar'), 'Not found bar in new collection manifest text'
38     assert manifest_text.include?('baz'), 'Not found baz in new collection manifest text'
39     assert manifest_text.include?('0:0:file1 0:0:file2 0:0:file3'),
40                 'Not found 0:0:file1 0:0:file2 0:0:file3 in new collection manifest text'
41     assert manifest_text.include?('dir1/subdir'), 'Not found dir1/subdir in new collection manifest text'
42     assert manifest_text.include?('dir2'), 'Not found dir2 in new collection manifest text'
43   end
44
45   test "combine files  with repeated names into new collection" do
46     post(:combine_selected_files_into_collection, {
47            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
48                        'zzzzz-4zz18-00000nonamecoll/foo',
49                        'zzzzz-4zz18-abcd6fx123409f7/foo',
50                        'zzzzz-4zz18-ehbhgtheo8909or/bar',
51                        'zzzzz-4zz18-y9vne9npefyxh8g/baz',
52                        '7a6ef4c162a5c6413070a8bd0bffc818+150'],
53            format: "json"},
54          session_for(:active))
55
56     assert_response 302   # collection created and redirected to new collection page
57
58     assert response.headers['Location'].include? '/collections/'
59     new_collection_uuid = response.headers['Location'].split('/')[-1]
60
61     use_token :active
62     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
63     manifest_text = collection['manifest_text']
64     assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
65     assert manifest_text.include?('foo(1)'), 'Not found foo(1) in new collection manifest text'
66     assert manifest_text.include?('foo(2)'), 'Not found foo(2) in new collection manifest text'
67     assert manifest_text.include?('bar'), 'Not found bar in new collection manifest text'
68     assert manifest_text.include?('baz'), 'Not found baz in new collection manifest text'
69     assert manifest_text.include?('0:0:file1 0:0:file2 0:0:file3'),
70                 'Not found 0:0:file1 0:0:file2 0:0:file3 in new collection manifest text'
71     assert manifest_text.include?('dir1/subdir'), 'Not found dir1/subdir in new collection manifest text'
72     assert manifest_text.include?('dir2'), 'Not found dir2 in new collection manifest text'
73   end
74
75   test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
76     post(:combine_selected_files_into_collection, {
77            selection: ['zzzzz-4zz18-duplicatenames1',
78                        'zzzzz-4zz18-duplicatenames2',
79                        'zzzzz-4zz18-znfnqtbbv4spc3w/foo',
80                        'zzzzz-4zz18-00000nonamecoll/foo',],
81            format: "json"},
82          session_for(:active))
83
84     assert_response 302   # collection created and redirected to new collection page
85
86     assert response.headers['Location'].include? '/collections/'
87     new_collection_uuid = response.headers['Location'].split('/')[-1]
88
89     use_token :active
90     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
91     manifest_text = collection['manifest_text']
92
93     assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
94     assert manifest_text.include?('foo(1)'), 'Not found foo(1) in new collection manifest text'
95
96     streams = manifest_text.split "\n"
97     streams.each do |stream|
98       if stream.start_with? './dir1'
99         # dir1 stream
100         assert stream.include?(':alice(1)'), "Not found: alice(1) in dir1 in manifest text #{manifest_text}"
101         assert stream.include?(':alice.txt'), "Not found: alice.txt in dir1 in manifest text #{manifest_text}"
102         assert stream.include?(':alice(1).txt'), "Not found: alice(1).txt in dir1 in manifest text #{manifest_text}"
103         assert stream.include?(':bob.txt'), "Not found: bob.txt in dir1 in manifest text #{manifest_text}"
104         assert stream.include?(':carol.txt'), "Not found: carol.txt in dir1 in manifest text #{manifest_text}"
105       elsif stream.start_with? './dir2'
106         # dir2 stream
107         assert stream.include?(':alice.txt'), "Not found: alice.txt in dir2 in manifest text #{manifest_text}"
108         assert stream.include?(':alice(1).txt'), "Not found: alice(1).txt in dir2 in manifest text #{manifest_text}"
109       elsif stream.start_with? '. '
110         # . stream
111         assert stream.include?(':foo'), "Not found: foo in . in manifest text #{manifest_text}"
112         assert stream.include?(':foo(1)'), "Not found: foo(1) in . in manifest text #{manifest_text}"
113       end
114     end
115   end
116
117   test "combine collections with same filename in two different streams and expect no suffixes for filenames" do
118     post(:combine_selected_files_into_collection, {
119            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w',
120                        'zzzzz-4zz18-foonbarfilesdir'],
121            format: "json"},
122          session_for(:active))
123
124     assert_response 302   # collection created and redirected to new collection page
125
126     assert response.headers['Location'].include? '/collections/'
127     new_collection_uuid = response.headers['Location'].split('/')[-1]
128
129     use_token :active
130     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
131     manifest_text = collection['manifest_text']
132
133     streams = manifest_text.split "\n"
134     assert_equal 2, streams.length
135     streams.each do |stream|
136       if stream.start_with? './dir1'
137         assert stream.include?('foo'), 'Not found: foo in dir1'
138       elsif stream.start_with? '. '
139         assert stream.include?('foo'), 'Not found: foo in .'
140       end
141     end
142     assert !manifest_text.include?('foo(1)'), 'Found foo(1) in new collection manifest text'
143   end
144
145   test "combine foo files from two different collection streams and expect proper filename suffixes" do
146     post(:combine_selected_files_into_collection, {
147            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
148                        'zzzzz-4zz18-foonbarfilesdir/dir1/foo'],
149            format: "json"},
150          session_for(:active))
151
152     assert_response 302   # collection created and redirected to new collection page
153
154     assert response.headers['Location'].include? '/collections/'
155     new_collection_uuid = response.headers['Location'].split('/')[-1]
156
157     use_token :active
158     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
159     manifest_text = collection['manifest_text']
160
161     streams = manifest_text.split "\n"
162     assert_equal 1, streams.length, "Incorrect number of streams in #{manifest_text}"
163     assert manifest_text.include?('foo'), "Not found foo in new collection manifest text #{manifest_text}"
164     assert manifest_text.include?('foo(1)'), "Not found foo(1) in new collection manifest text #{manifest_text}"
165   end
166 end