2411: Add copyright notices to everything.
[arvados.git] / services / api / test / functional / arvados / v1 / collections_controller_test.rb
index 055af9e67cffe4fc93d44aea5d70f11b23948b6d..56b0790a0a5e3920968e6ff580f5909f301941bc 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'test_helper'
 
 class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
@@ -1045,7 +1049,7 @@ EOS
 
   [:active, :admin].each do |user|
     test "get trashed collections as #{user}" do
-      authorize_with :active
+      authorize_with user
       get :index, {
         filters: [["is_trashed", "=", true]],
         include_trash: true,
@@ -1065,4 +1069,25 @@ EOS
       end
     end
   end
+
+  test 'untrash collection with same name as another with no ensure unique name' do
+    authorize_with :active
+    post :untrash, {
+      id: collections(:trashed_collection_to_test_name_conflict_on_untrash).uuid,
+    }
+    assert_response 422
+  end
+
+  test 'untrash collection with same name as another with ensure unique name' do
+    authorize_with :active
+    post :untrash, {
+      id: collections(:trashed_collection_to_test_name_conflict_on_untrash).uuid,
+      ensure_unique_name: true
+    }
+    assert_response 200
+    assert_equal false, json_response['is_trashed']
+    assert_nil json_response['trash_at']
+    assert_nil json_response['delete_at']
+    assert_match /^same name for trashed and persisted collections \(\d{4}-\d\d-\d\d.*?Z\)$/, json_response['name']
+  end
 end