15227: More tests to expose the bug.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 17 May 2019 00:19:57 +0000 (21:19 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 17 May 2019 00:19:57 +0000 (21:19 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

services/api/test/functional/arvados/v1/collections_controller_test.rb
services/api/test/integration/collections_api_test.rb

index 244fa0ce585dad477abc81c2f5ac271a4b033f04..089895864adc3f9322eb6f97ca5244af021e876d 100644 (file)
@@ -924,19 +924,25 @@ EOS
     assert_equal 'value1', json_response['properties']['property1']
   end
 
-  test "create collection with properties" do
-    authorize_with :active
-    manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
-    post :create, params: {
-      collection: {
-        manifest_text: manifest_text,
-        portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
-        properties: {'property_1' => 'value_1'}
+  [
+    {'property_1' => 'value_1'},
+    "{\"property_1\":\"value_1\"}",
+  ].each do |p|
+    test "create collection with valid properties param #{p.inspect}" do
+      authorize_with :active
+      manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
+      post :create, params: {
+        collection: {
+          manifest_text: manifest_text,
+          portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
+          properties: p
+        }
       }
-    }
-    assert_response :success
-    assert_not_nil json_response['uuid']
-    assert_equal 'value_1', json_response['properties']['property_1']
+      assert_response :success
+      assert_not_nil json_response['uuid']
+      assert_equal Hash, json_response['properties'].class, 'Collection properties attribute should be of type hash'
+      assert_equal 'value_1', json_response['properties']['property_1']
+    end
   end
 
   [
@@ -944,7 +950,7 @@ EOS
     [],
     42,
     'some string',
-    '["json", "encoded", "list"]',
+    '["json", "encoded", "array"]',
   ].each do |p|
     test "create collection with non-valid properties param #{p.inspect}" do
       authorize_with :active
index ab1a3e69de4a10ac6d623769ca126b6cf6909b78..eb44b9b34ead7bc858ce700c441cc3377f4de1b0 100644 (file)
@@ -358,7 +358,7 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
     assert_not_nil json_response['properties']
     assert_empty json_response['properties']
 
-    # update collection's description
+    # update collection's properties
     put "/arvados/v1/collections/#{json_response['uuid']}",
       params: {
         format: :json,
@@ -366,6 +366,35 @@ class CollectionsApiTest < ActionDispatch::IntegrationTest
       },
       headers: auth(:active)
     assert_response :success
+    assert_equal Hash, json_response['properties'].class, 'Collection properties attribute should be of type hash'
+    assert_equal 'value_1', json_response['properties']['property_1']
+  end
+
+  test "create collection and update it with json encoded hash properties" do
+    # create collection to be searched for
+    signed_manifest = Collection.sign_manifest(". bad42fa702ae3ea7d888fef11b46f450+44 0:44:my_test_file.txt\n", api_token(:active))
+    post "/arvados/v1/collections",
+      params: {
+        format: :json,
+        collection: {manifest_text: signed_manifest}.to_json,
+      },
+      headers: auth(:active)
+    assert_response 200
+    assert_not_nil json_response['uuid']
+    assert_not_nil json_response['properties']
+    assert_empty json_response['properties']
+
+    # update collection's properties
+    put "/arvados/v1/collections/#{json_response['uuid']}",
+      params: {
+        format: :json,
+        collection: {
+          properties: "{\"property_1\":\"value_1\"}"
+        }
+      },
+      headers: auth(:active)
+    assert_response :success
+    assert_equal Hash, json_response['properties'].class, 'Collection properties attribute should be of type hash'
     assert_equal 'value_1', json_response['properties']['property_1']
   end
 end