Merge branch '10346-rearrange-api-docs' closes #10346
[arvados.git] / services / api / test / functional / arvados / v1 / collections_controller_test.rb
index 99b03332567da7e3f52331acb6f3c63ead6415e2..c85cc1979f99482ff36ba6dc38ba5790ec7bf591 100644 (file)
@@ -46,6 +46,49 @@ class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
     end
   end
 
+  test 'index without select returns everything except manifest' do
+    authorize_with :active
+    get :index
+    assert_response :success
+    assert json_response['items'].any?
+    json_response['items'].each do |coll|
+      assert_includes(coll.keys, 'uuid')
+      assert_includes(coll.keys, 'name')
+      assert_includes(coll.keys, 'created_at')
+      refute_includes(coll.keys, 'manifest_text')
+    end
+  end
+
+  ['', nil, false, 'null'].each do |select|
+    test "index with select=#{select.inspect} returns everything except manifest" do
+      authorize_with :active
+      get :index, select: select
+      assert_response :success
+      assert json_response['items'].any?
+      json_response['items'].each do |coll|
+        assert_includes(coll.keys, 'uuid')
+        assert_includes(coll.keys, 'name')
+        assert_includes(coll.keys, 'created_at')
+        refute_includes(coll.keys, 'manifest_text')
+      end
+    end
+  end
+
+  [["uuid"],
+   ["uuid", "manifest_text"],
+   '["uuid"]',
+   '["uuid", "manifest_text"]'].each do |select|
+    test "index with select=#{select.inspect} returns no name" do
+      authorize_with :active
+      get :index, select: select
+      assert_response :success
+      assert json_response['items'].any?
+      json_response['items'].each do |coll|
+        refute_includes(coll.keys, 'name')
+      end
+    end
+  end
+
   [0,1,2].each do |limit|
     test "get index with limit=#{limit}" do
       authorize_with :active
@@ -811,13 +854,12 @@ EOS
   end
 
   [
-    nil,
     ". 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
     "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
   ].each do |manifest_text|
-    test "create collection with invalid manifest #{manifest_text}" do
+    test "create collection with invalid manifest #{manifest_text} and expect error" do
       authorize_with :active
       post :create, {
         collection: {
@@ -825,26 +867,38 @@ EOS
           portable_data_hash: "d41d8cd98f00b204e9800998ecf8427e+0"
         }
       }
-      if manifest_text
-        assert_response 422
-        response_errors = json_response['errors']
-        assert_not_nil response_errors, 'Expected error in response'
-        assert(response_errors.first.include?('Invalid manifest'),
-               "Expected 'Invalid manifest' error in #{response_errors.first}")
-      else
-        assert_response 200
-      end
+      assert_response 422
+      response_errors = json_response['errors']
+      assert_not_nil response_errors, 'Expected error in response'
+      assert(response_errors.first.include?('Invalid manifest'),
+             "Expected 'Invalid manifest' error in #{response_errors.first}")
+    end
+  end
+
+  [
+    [nil, "d41d8cd98f00b204e9800998ecf8427e+0"],
+    ["", "d41d8cd98f00b204e9800998ecf8427e+0"],
+    [". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n", "d30fe8ae534397864cb96c544f4cf102+47"],
+  ].each do |manifest_text, pdh|
+    test "create collection with valid manifest #{manifest_text.inspect} and expect success" do
+      authorize_with :active
+      post :create, {
+        collection: {
+          manifest_text: manifest_text,
+          portable_data_hash: pdh
+        }
+      }
+      assert_response 200
     end
   end
 
   [
-    nil,
     ". 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
     "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
     ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
   ].each do |manifest_text|
-    test "update collection with invalid manifest #{manifest_text}" do
+    test "update collection with invalid manifest #{manifest_text} and expect error" do
       authorize_with :active
       post :update, {
         id: 'zzzzz-4zz18-bv31uwvy3neko21',
@@ -852,15 +906,28 @@ EOS
           manifest_text: manifest_text,
         }
       }
-      if manifest_text
-        assert_response 422
-        response_errors = json_response['errors']
-        assert_not_nil response_errors, 'Expected error in response'
-        assert(response_errors.first.include?('Invalid manifest'),
-               "Expected 'Invalid manifest' error in #{response_errors.first}")
-      else
-        assert_response 200
-      end
+      assert_response 422
+      response_errors = json_response['errors']
+      assert_not_nil response_errors, 'Expected error in response'
+      assert(response_errors.first.include?('Invalid manifest'),
+             "Expected 'Invalid manifest' error in #{response_errors.first}")
+    end
+  end
+
+  [
+    nil,
+    "",
+    ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
+  ].each do |manifest_text|
+    test "update collection with valid manifest #{manifest_text.inspect} and expect success" do
+      authorize_with :active
+      post :update, {
+        id: 'zzzzz-4zz18-bv31uwvy3neko21',
+        collection: {
+          manifest_text: manifest_text,
+        }
+      }
+      assert_response 200
     end
   end
 end