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
include startTime and endTime in the response for TimeEntries
Klaus Zanders277f5c8a4e74
diff --git a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rbindex ad87f115e7a..643648f251b 100644--- a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb+++ b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb@@ -88,6 +88,16 @@ module APIdatetime_formatter.format_duration_from_hours(represented.hours) if represented.hoursend+ date_time_property :start_time,+ exec_context: :decorator,+ getter: ->(*) { represented.start_timestamp },+ if: ->(*) { TimeEntry.can_track_start_and_end_time? }++ date_time_property :end_time,+ exec_context: :decorator,+ getter: ->(*) { represented.end_timestamp },+ if: ->(*) { TimeEntry.can_track_start_and_end_time? }+date_time_property :created_atdate_time_property :updated_atdiff --git a/modules/costs/spec/factories/time_entry_factory.rb b/modules/costs/spec/factories/time_entry_factory.rbindex 325985cff30..43c1aac95b7 100644--- a/modules/costs/spec/factories/time_entry_factory.rb+++ b/modules/costs/spec/factories/time_entry_factory.rb@@ -38,5 +38,11 @@ FactoryBot.define doafter(:build) do |time_entry|time_entry.project ||= time_entry.work_package.projectend++ trait :with_start_and_end_time do+ time_zone { "Asia/Tokyo" }+ start_time { 390 } # 6:30 AM+ hours { 2.5 }+ endendenddiff --git a/modules/costs/spec/requests/api/time_entry_resource_spec.rb b/modules/costs/spec/requests/api/time_entry_resource_spec.rbindex 1117df243b1..7d54ce1f2f0 100644--- a/modules/costs/spec/requests/api/time_entry_resource_spec.rb+++ b/modules/costs/spec/requests/api/time_entry_resource_spec.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -330,6 +332,76 @@ RSpec.describe "API v3 time_entry resource" do.at_path("errorIdentifier")endend++ context "when start- & end-time tracking is enabled",+ with_flag: { track_start_and_end_times_for_time_entries: true },+ with_settings: { allow_tracking_start_and_end_times: true } do+ context "when start and end time were tracked" do+ let!(:time_entry) do+ create(:time_entry, :with_start_and_end_time, project:, work_package:, user: current_user)+ end++ it "includes start and end timestamps in the API response" do+ get api_v3_paths.time_entries++ expect(subject.body)+ .to be_json_eql(time_entry.start_timestamp.to_json)+ .at_path("_embedded/elements/0/startTime")++ expect(subject.body)+ .to be_json_eql(time_entry.end_timestamp.to_json)+ .at_path("_embedded/elements/0/endTime")+ end+ end++ context "when start and end time were not tracked" do+ let!(:time_entry) do+ create(:time_entry, project:, work_package:, user: current_user)+ end++ it "returns nil as start and end timestamps in the API response" do+ get api_v3_paths.time_entries++ expect(subject.body)+ .to be_json_eql(nil.to_json)+ .at_path("_embedded/elements/0/startTime")++ expect(subject.body)+ .to be_json_eql(nil.to_json)+ .at_path("_embedded/elements/0/endTime")+ end+ end+ end++ context "when start- & end-time tracking is disabled",+ with_flag: { track_start_and_end_times_for_time_entries: false },+ with_settings: { allow_tracking_start_and_end_times: false } do+ context "when start and end time were tracked" do+ let!(:time_entry) do+ create(:time_entry, :with_start_and_end_time, project:, work_package:, user: current_user)+ end++ it "does not include start and end time fields" do+ get api_v3_paths.time_entries++ expect(subject.body).not_to have_json_path("_embedded/elements/0/startTime")+ expect(subject.body).not_to have_json_path("_embedded/elements/0/endTime")+ end+ end++ context "when start and end time were not tracked" do+ let!(:time_entry) do+ create(:time_entry, project:, work_package:, user: current_user)+ end++ it "does not include start and end time fields" do+ get api_v3_paths.time_entries++ expect(subject.body).not_to have_json_path("_embedded/elements/0/startTime")+ expect(subject.body).not_to have_json_path("_embedded/elements/0/endTime")+ end+ end+ endenddescribe "GET /api/v3/time_entries/:id" do@@ -617,7 +689,7 @@ RSpec.describe "API v3 time_entry resource" doendit "removes the time_entry from the DB" do- expect(TimeEntry.exists?(time_entry.id)).to be_falsey+ expect(TimeEntry).not_to exist(time_entry.id)endend@@ -627,7 +699,7 @@ RSpec.describe "API v3 time_entry resource" doendit "does not delete the time_entry" do- expect(TimeEntry.exists?(time_entry.id)).to be_truthy+ expect(TimeEntry).to exist(time_entry.id)endend