Skip to content

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

[#66093] Project API calculation error spec

Tobias Dillmannc2df8f30edd1
diff --git a/spec/factories/calculated_value_error_factory.rb b/spec/factories/calculated_value_error_factory.rb
new file mode 100644
index 00000000000..695df17273d
--- /dev/null
+++ b/spec/factories/calculated_value_error_factory.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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.
+#++
+
+FactoryBot.define do
+ factory :calculated_value_error do
+ error_code { "ERROR_MATHEMATICAL" }
+ end
+end
diff --git a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
index 35e825a48ed..4805b3c935c 100644
--- a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
@@ -215,6 +215,33 @@ RSpec.describe API::V3::Projects::ProjectRepresenter, "rendering" do
expect(subject).to be_json_eql(calculated_custom_value.value.to_json)
.at_path(cf_path)
end
+
+ context "when there is a calculation error" do
+ let(:cf_path) { "customField#{calculated_value_custom_field.id}errors" }
+
+ let!(:calculated_value_error) do
+ build_stubbed(:calculated_value_error, custom_field: calculated_value_custom_field, project: project)
+ end
+
+ before do
+ value_errors_double = double
+ allow(value_errors_double).to receive(:where)
+ .with(project_id: project.id)
+ .and_return([calculated_value_error])
+
+ allow(calculated_value_custom_field).to receive(:calculated_value_errors)
+ .and_return(value_errors_double)
+ end
+
+ it "has a property for calculation errors" do
+ expect(subject).to be_json_eql([
+ {
+ error_code: "ERROR_MATHEMATICAL",
+ error_message: I18n.t("calculated_values.errors.mathematical")
+ }
+ ].to_json).at_path(cf_path)
+ end
+ end
end
end