From 921783ecec893414d328becf3d3da2c34fd5e2f0 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Thu, 16 May 2019 21:19:57 -0300 Subject: [PATCH] 15227: More tests to expose the bug. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../arvados/v1/collections_controller_test.rb | 32 +++++++++++-------- .../test/integration/collections_api_test.rb | 31 +++++++++++++++++- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/services/api/test/functional/arvados/v1/collections_controller_test.rb b/services/api/test/functional/arvados/v1/collections_controller_test.rb index 244fa0ce58..089895864a 100644 --- a/services/api/test/functional/arvados/v1/collections_controller_test.rb +++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb @@ -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 diff --git a/services/api/test/integration/collections_api_test.rb b/services/api/test/integration/collections_api_test.rb index ab1a3e69de..eb44b9b34e 100644 --- a/services/api/test/integration/collections_api_test.rb +++ b/services/api/test/integration/collections_api_test.rb @@ -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 -- 2.39.5