+ assert_equal ask, json_response['replication_desired']
+ end
+ end
+
+ test "get collection with properties" do
+ authorize_with :active
+ get :show, {id: collections(:collection_with_one_property).uuid}
+ assert_response :success
+ assert_not_nil json_response['uuid']
+ 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, {
+ collection: {
+ manifest_text: manifest_text,
+ portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
+ properties: {'property_1' => 'value_1'}
+ }
+ }
+ assert_response :success
+ assert_not_nil json_response['uuid']
+ assert_equal 'value_1', json_response['properties']['property_1']
+ end
+
+ [
+ ". 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
+ "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ].each do |manifest_text|
+ test "create collection with invalid manifest #{manifest_text} and expect error" do
+ authorize_with :active
+ post :create, {
+ collection: {
+ manifest_text: manifest_text,
+ portable_data_hash: "d41d8cd98f00b204e9800998ecf8427e+0"
+ }
+ }
+ assert_response 422
+ response_errors = json_response['errors']
+ assert_not_nil response_errors, 'Expected error in response'
+ assert(response_errors.first.include?('Invalid manifest'),
+ "Expected 'Invalid manifest' error in #{response_errors.first}")
+ end
+ end
+
+ [
+ [nil, "d41d8cd98f00b204e9800998ecf8427e+0"],
+ ["", "d41d8cd98f00b204e9800998ecf8427e+0"],
+ [". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n", "d30fe8ae534397864cb96c544f4cf102+47"],
+ ].each do |manifest_text, pdh|
+ test "create collection with valid manifest #{manifest_text.inspect} and expect success" do
+ authorize_with :active
+ post :create, {
+ collection: {
+ manifest_text: manifest_text,
+ portable_data_hash: pdh
+ }
+ }
+ assert_response 200
+ end
+ end
+
+ [
+ ". 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
+ "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ].each do |manifest_text|
+ test "update collection with invalid manifest #{manifest_text} and expect error" do
+ authorize_with :active
+ post :update, {
+ id: 'zzzzz-4zz18-bv31uwvy3neko21',
+ collection: {
+ manifest_text: manifest_text,
+ }
+ }
+ assert_response 422
+ response_errors = json_response['errors']
+ assert_not_nil response_errors, 'Expected error in response'
+ assert(response_errors.first.include?('Invalid manifest'),
+ "Expected 'Invalid manifest' error in #{response_errors.first}")
+ end
+ end
+
+ [
+ nil,
+ "",
+ ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
+ ].each do |manifest_text|
+ test "update collection with valid manifest #{manifest_text.inspect} and expect success" do
+ authorize_with :active
+ post :update, {
+ id: 'zzzzz-4zz18-bv31uwvy3neko21',
+ collection: {
+ manifest_text: manifest_text,
+ }
+ }
+ assert_response 200
+ end
+ end
+
+ test 'get trashed collection with include_trash' do
+ uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection
+ authorize_with :active
+ get :show, {
+ id: uuid,
+ include_trash: true,
+ }
+ assert_response 200
+ end
+
+ test 'get trashed collection without include_trash' do
+ uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection
+ authorize_with :active
+ get :show, {
+ id: uuid,
+ }
+ assert_response 404
+ end
+
+ test 'trash collection using http DELETE verb' do
+ uuid = collections(:collection_owned_by_active).uuid
+ authorize_with :active
+ delete :destroy, {
+ id: uuid,
+ }
+ assert_response 200
+ c = Collection.unscoped.find_by_uuid(uuid)
+ assert_operator c.trash_at, :<, db_current_time
+ assert_equal c.delete_at, c.trash_at + Rails.configuration.blob_signature_ttl
+ end
+
+ test 'delete long-trashed collection immediately using http DELETE verb' do
+ uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection
+ authorize_with :active
+ delete :destroy, {
+ id: uuid,
+ }
+ assert_response 200
+ c = Collection.unscoped.find_by_uuid(uuid)
+ assert_operator c.trash_at, :<, db_current_time
+ assert_operator c.delete_at, :<, db_current_time
+ end
+
+ ['zzzzz-4zz18-mto52zx1s7sn3ih', # expired_collection
+ :empty_collection_name_in_active_user_home_project,
+ ].each do |fixture|
+ test "trash collection #{fixture} via trash action with grace period" do
+ if fixture.is_a? String
+ uuid = fixture
+ else
+ uuid = collections(fixture).uuid
+ end
+ authorize_with :active
+ time_before_trashing = db_current_time
+ post :trash, {
+ id: uuid,
+ }
+ assert_response 200
+ c = Collection.unscoped.find_by_uuid(uuid)
+ assert_operator c.trash_at, :<, db_current_time
+ assert_operator c.delete_at, :>=, time_before_trashing + Rails.configuration.default_trash_lifetime