From f40197dc1a03b1da0a66590136d661fd245c7595 Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Wed, 23 Mar 2022 09:54:19 +0100 Subject: [PATCH] turn Storages::FileLinks::CreateContract into a ModelContract + display more information in test if there are contract errors --- .../storages/file_links/create_contract.rb | 16 +++++++++++++++- .../api/v3/support/api_v3_collection_response.rb | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/storages/app/contracts/storages/file_links/create_contract.rb b/modules/storages/app/contracts/storages/file_links/create_contract.rb index c873542984..f694dfc954 100644 --- a/modules/storages/app/contracts/storages/file_links/create_contract.rb +++ b/modules/storages/app/contracts/storages/file_links/create_contract.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 diff --git a/spec/requests/api/v3/support/api_v3_collection_response.rb b/spec/requests/api/v3/support/api_v3_collection_response.rb index a2b8ec73c8..15559403c6 100644 --- a/spec/requests/api/v3/support/api_v3_collection_response.rb +++ b/spec/requests/api/v3/support/api_v3_collection_response.rb @@ -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')