OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Started implementing a FileLinkRepresenter parsing
Christophe Bliardf7f9bede6709
diff --git a/modules/storages/lib/api/v3/file_links/file_link_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_representer.rbindex cdfc651842b..f7079fa8e94 100644--- a/modules/storages/lib/api/v3/file_links/file_link_representer.rb+++ b/modules/storages/lib/api/v3/file_links/file_link_representer.rb@@ -41,7 +41,10 @@ module APIproperty :originData,exec_context: :decorator,- getter: ->(*) { make_origin_data(represented) }+ getter: ->(*) { make_origin_data(represented) },+ setter: ->(fragment:, **) do+ represented.assign_attributes(parse_origin_data(fragment))+ endlink :self do{@@ -103,6 +106,17 @@ module APIlastModifiedByName: model.origin_last_modified_by_name}end++ def parse_origin_data(origin_data)+ {+ origin_id: origin_data["id"].to_s,+ origin_name: origin_data["name"],+ origin_mime_type: origin_data["mimeType"],+ origin_created_by_name: origin_data["createdByName"],+ origin_last_modified_by_name: origin_data["lastModifiedByName"]+ # createdAt and lastModifiedAt to be done+ }+ endendendenddiff --git a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_parsing_spec.rb b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_parsing_spec.rbnew file mode 100644index 00000000000..a1e003994fd--- /dev/null+++ b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_parsing_spec.rb@@ -0,0 +1,76 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++describe ::API::V3::FileLinks::FileLinkRepresenter, 'parsing' do+ # include ::API::V3::Utilities::PathHelper++ let(:file_link) { build_stubbed(:file_link) }++ current_user { build_stubbed(:user) }++ describe 'parsing' do+ subject(:parsed) { representer.from_hash parsed_hash }++ let(:representer) do+ described_class.create(file_link, current_user: current_user)+ end++ context 'with originData given' do+ let(:parsed_hash) do+ {+ "_type" => "FileLink",+ "createdAt" => "2022-02-09T10:03:37Z",+ "updatedAt" => "2022-02-09T10:03:37Z",+ "originData" => {+ "id" => 5503,+ "name" => "logo.png",+ "mimeType" => "image/png",+ "createdAt" => "2021-12-19T09:42:10.170Z",+ "lastModifiedAt" => "2021-12-20T14:00:13.987Z",+ "createdByName" => "Luke Skywalker",+ "lastModifiedByName" => "Anakin Skywalker"+ }+ }+ end++ it 'parses correctly', pending: "work in progress" do+ expect(parsed).to have_attributes(+ origin_id: "5503",+ origin_name: "logo.png",+ origin_mime_type: "image/png",+ origin_created_by_name: "Luke Skywalker",+ origin_last_modified_by_name: "Anakin Skywalker",+ origin_created_at: "to be done",+ orig_updated_at: "to be done"+ )+ end+ end+ end+enddiff --git a/spec/lib/api/v3/utilities/date_time_formatter_spec.rb b/spec/lib/api/v3/utilities/date_time_formatter_spec.rbindex 069369136ca..68ef36e3472 100644--- a/spec/lib/api/v3/utilities/date_time_formatter_spec.rb+++ b/spec/lib/api/v3/utilities/date_time_formatter_spec.rb@@ -79,14 +79,20 @@ describe :DateTimeFormatter dobad_format = date.strftime('%d.%m.%Y')expect dosubject.parse_date(bad_format, 'prop')- end.to raise_error(API::Errors::PropertyFormatError)+ end.to raise_error(API::Errors::PropertyFormatError) do |error| # rubocop:disable Style/MultilineBlockChain+ expect(error.message).to include("Invalid format for property 'prop'")+ expect(error.message).to include("Expected format like 'YYYY-MM-DD (ISO 8601 date only)'")+ endendit 'rejects parsing ISO 8601 date + time formats' dobad_format = datetime.iso8601expect dosubject.parse_date(bad_format, 'prop')- end.to raise_error(API::Errors::PropertyFormatError)+ end.to raise_error(API::Errors::PropertyFormatError) do |error| # rubocop:disable Style/MultilineBlockChain+ expect(error.message).to include("Invalid format for property 'prop'")+ expect(error.message).to include("Expected format like 'YYYY-MM-DD (ISO 8601 date only)'")+ endendit_behaves_like 'can parse nil' do