Merge branch '8784-dir-listings'
[arvados.git] / services / api / test / integration / valid_links_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class ValidLinksTest < ActionDispatch::IntegrationTest
8   fixtures :all
9
10   test "tail must exist on update" do
11     admin_auth = {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
12
13     post "/arvados/v1/links", {
14       :format => :json,
15       :link => {
16         link_class: 'test',
17         name: 'stuff',
18         head_uuid: users(:active).uuid,
19         tail_uuid: virtual_machines(:testvm).uuid
20       }
21     }, admin_auth
22     assert_response :success
23     u = json_response['uuid']
24
25     put "/arvados/v1/links/#{u}", {
26       :format => :json,
27       :link => {
28         tail_uuid: virtual_machines(:testvm2).uuid
29       }
30     }, admin_auth
31     assert_response :success
32     assert_equal virtual_machines(:testvm2).uuid, (ActiveSupport::JSON.decode @response.body)['tail_uuid']
33
34     put "/arvados/v1/links/#{u}", {
35       :format => :json,
36       :link => {
37         tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
38       }
39     }, admin_auth
40     assert_response 422
41   end
42
43 end