Merge branch 'master' of git.curoverse.com:arvados into 2612-workbench-displays-user...
[arvados.git] / services / api / test / integration / collections_api_test.rb
1 require 'test_helper'
2
3 class CollectionsApiTest < ActionDispatch::IntegrationTest
4   fixtures :all
5
6   test "should get index" do
7     get "/arvados/v1/collections", {:format => :json}, auth(:active)
8     assert_response :success
9     assert_equal "arvados#collectionList", jresponse['kind']
10   end
11
12   test "get index with filters= (empty string)" do
13     get "/arvados/v1/collections", {:format => :json, :filters => ''}, auth(:active)
14     assert_response :success
15     assert_equal "arvados#collectionList", jresponse['kind']
16   end
17
18   test "get index with invalid filters (array of strings) responds 422" do
19     get "/arvados/v1/collections", {
20       :format => :json,
21       :filters => ['uuid', '=', 'ad02e37b6a7f45bbe2ead3c29a109b8a+54'].to_json
22     }, auth(:active)
23     assert_response 422
24     assert_match /nvalid element.*not an array/, jresponse['errors'].join(' ')
25   end
26
27   test "get index with invalid filters (unsearchable column) responds 422" do
28     get "/arvados/v1/collections", {
29       :format => :json,
30       :filters => [['this_column_does_not_exist', '=', 'bogus']].to_json
31     }, auth(:active)
32     assert_response 422
33     assert_match /nvalid attribute/, jresponse['errors'].join(' ')
34   end
35
36   test "get index with invalid filters (invalid operator) responds 422" do
37     get "/arvados/v1/collections", {
38       :format => :json,
39       :filters => [['uuid', ':-(', 'displeased']].to_json
40     }, auth(:active)
41     assert_response 422
42     assert_match /nvalid operator/, jresponse['errors'].join(' ')
43   end
44
45   test "get index with invalid filters (invalid operand type) responds 422" do
46     get "/arvados/v1/collections", {
47       :format => :json,
48       :filters => [['uuid', '=', {foo: 'bar'}]].to_json
49     }, auth(:active)
50     assert_response 422
51     assert_match /nvalid operand type/, jresponse['errors'].join(' ')
52   end
53
54   test "get index with where= (empty string)" do
55     get "/arvados/v1/collections", {:format => :json, :where => ''}, auth(:active)
56     assert_response :success
57     assert_equal "arvados#collectionList", jresponse['kind']
58   end
59
60   test "controller 404 response is json" do
61     get "/arvados/v1/thingsthatdonotexist", {:format => :xml}, auth(:active)
62     assert_response 404
63     assert_equal 1, jresponse['errors'].length
64     assert_equal true, jresponse['errors'][0].is_a?(String)
65   end
66
67   test "object 404 response is json" do
68     get "/arvados/v1/groups/zzzzz-j7d0g-o5ba971173cup4f", {}, auth(:active)
69     assert_response 404
70     assert_equal 1, jresponse['errors'].length
71     assert_equal true, jresponse['errors'][0].is_a?(String)
72   end
73
74   test "store collection as json" do
75     post "/arvados/v1/collections", {
76       format: :json,
77       collection: "{\"manifest_text\":\". bad42fa702ae3ea7d888fef11b46f450+44 0:44:md5sum.txt\\n\",\"uuid\":\"ad02e37b6a7f45bbe2ead3c29a109b8a+54\"}"
78     }, auth(:active)
79     assert_response 200
80     assert_equal 'ad02e37b6a7f45bbe2ead3c29a109b8a+54', jresponse['uuid']
81   end
82 end