turn Storages::FileLinks::CreateContract into a ModelContract

+ display more information in test if there are contract errors
pull/10387/head
Christophe Bliard 3 years ago
parent 248da19f03
commit f40197dc1a
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 16
      modules/storages/app/contracts/storages/file_links/create_contract.rb
  2. 7
      spec/requests/api/v3/support/api_v3_collection_response.rb

@ -26,7 +26,21 @@
# See COPYRIGHT and LICENSE files for more details.
#++
class Storages::FileLinks::CreateContract < BaseContract
class Storages::FileLinks::CreateContract < ModelContract
attribute :name
attribute :storage
attribute :creator
attribute :container
attribute :container_type
attribute :origin_id
attribute :origin_name
attribute :origin_created_by_name
attribute :origin_last_modified_by_name
attribute :origin_mime_type
attribute :origin_created_at
attribute :origin_updated_at
validate :validate_storage_presence
validate :validate_user_allowed_to_manage
validate :validate_project_storage_link

@ -60,6 +60,13 @@ shared_examples_for 'API V3 collection response' do |total, count, element_type,
it 'returns a collection successfully' do
aggregate_failures do
expect(last_response.status).to eq(expected_status_code)
errors = JSON.parse(subject).dig("_embedded", "errors")&.map { _1["message"] }
expect(errors).to eq([]) if errors # make errors visible in console if any
end
end
it 'contains all elements' do
aggregate_failures do
expect(subject).to be_json_eql(collection_type.to_json).at_path('_type')
expect(subject).to be_json_eql(count_number.to_json).at_path('count')
expect(subject).to be_json_eql(total_number.to_json).at_path('total')

Loading…
Cancel
Save