Merge branch '21383-misc-fixes'. Refs #21383
[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       params: {
15         :format => :json,
16         :link => {
17           link_class: 'test',
18           name: 'stuff',
19           head_uuid: users(:active).uuid,
20           tail_uuid: virtual_machines(:testvm).uuid
21         }
22       },
23       headers: admin_auth
24     assert_response :success
25     u = json_response['uuid']
26
27     put "/arvados/v1/links/#{u}",
28       params: {
29         :format => :json,
30         :link => {
31           tail_uuid: virtual_machines(:testvm2).uuid
32         }
33       },
34       headers: admin_auth
35     assert_response :success
36     assert_equal virtual_machines(:testvm2).uuid, (ActiveSupport::JSON.decode @response.body)['tail_uuid']
37
38     put "/arvados/v1/links/#{u}",
39       params: {
40         :format => :json,
41         :link => {
42           tail_uuid: 'zzzzz-tpzed-xyzxyzxerrrorxx'
43         }
44       },
45       headers: admin_auth
46     assert_response 422
47   end
48
49 end