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

baseline api: fixing test issue with relative timestamps

Sebastian Fiedlschusterf1df4a35586e
diff --git a/spec/models/journable/with_historic_attributes_spec.rb b/spec/models/journable/with_historic_attributes_spec.rb
index 8879939bd47..50b8dc15a45 100644
--- a/spec/models/journable/with_historic_attributes_spec.rb
+++ b/spec/models/journable/with_historic_attributes_spec.rb
@@ -443,6 +443,18 @@ describe Journable::WithHistoricAttributes do
end
end
end
+
+ context "with multiple relative and absolute timestamps" do
+ let(:timestamps) do
+ [Timestamp.parse("2015-01-01T00:00:00Z"), Timestamp.parse("P-1Y"),
+ Timestamp.parse("2022-01-01T00:00:00Z"), Timestamp.parse("PT0S")]
+ end
+ let(:work_packages) { [work_package] }
+
+ it "preserves the relative character of the timestamps" do
+ expect(subject.first.timestamps.map(&:relative?)).to eq [false, true, false, true]
+ end
+ end
end
describe "#baseline_timestamp" do
diff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rb
index 4e7f7d9ae2e..5f8c11aca1f 100644
--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb
@@ -339,8 +339,20 @@ describe 'API v3 Work package resource',
.not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/timestamp")
end
+ it 'has the relative timestamps within the _meta timestamps' do
+ expect(subject.body)
+ .to be_json_eql('2015-01-01T00:00:00Z'.to_json)
+ .at_path('_embedded/elements/0/_embedded/attributesByTimestamp/0/_meta/timestamp')
+ expect(subject.body)
+ .to be_json_eql('PT0S'.to_json)
+ .at_path('_embedded/elements/0/_embedded/attributesByTimestamp/1/_meta/timestamp')
+ expect(subject.body)
+ .to be_json_eql('PT0S'.to_json)
+ .at_path('_embedded/elements/0/_meta/timestamp')
+ end
+
describe "when filtering such that the filters do not match at all timestamps" do
- let(:path) { api_v3_paths.path_for :work_packages, filters:, timestamps: }
+ let(:path) { "#{api_v3_paths.path_for(:work_packages, filters:)}&timestamps=#{timestamps.join(',')}" }
let(:filters) do
[
{
@@ -752,6 +764,20 @@ describe 'API v3 Work package resource',
end
let(:search_term) { 'original' }
+ it 'has the relative timestamps within the _meta timestamps' do
+ expect(timestamps.first.to_s).to eq('P-2D')
+ expect(timestamps.first).to be_relative
+ expect(subject.body)
+ .to be_json_eql('P-2D'.to_json)
+ .at_path('_embedded/elements/0/_embedded/attributesByTimestamp/0/_meta/timestamp')
+ expect(subject.body)
+ .to be_json_eql('PT0S'.to_json)
+ .at_path('_embedded/elements/0/_embedded/attributesByTimestamp/1/_meta/timestamp')
+ expect(subject.body)
+ .to be_json_eql('PT0S'.to_json)
+ .at_path('_embedded/elements/0/_meta/timestamp')
+ end
+
it "does not use an outdated cache" do
get path
expect do
diff --git a/spec/requests/api/v3/work_packages/show_resource_spec.rb b/spec/requests/api/v3/work_packages/show_resource_spec.rb
index a19d4f96fd6..f35c24b82d6 100644
--- a/spec/requests/api/v3/work_packages/show_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb
@@ -259,21 +259,6 @@ describe 'API v3 Work package resource',
expect(subject && last_response.status).to eq(200)
end
- it 'embeds the attributesByTimestamp' do
- expect(subject)
- .to be_json_eql("The original work package".to_json)
- .at_path("_embedded/attributesByTimestamp/0/subject")
- expect(subject)
- .to have_json_path("_embedded/attributesByTimestamp/1")
- end
-
- it 'does not embed the attributes in attributesByTimestamp if they are the same as the current attributes' do
- expect(subject)
- .not_to have_json_path("_embedded/attributesByTimestamp/0/description")
- expect(subject)
- .not_to have_json_path("_embedded/attributesByTimestamp/1/description")
- end
-
it 'has the current attributes as attributes' do
expect(subject)
.to be_json_eql("The current work package".to_json)
@@ -294,6 +279,36 @@ describe 'API v3 Work package resource',
end
end
+ describe "attributesByTimestamp" do
+ it 'embeds the attributesByTimestamp' do
+ expect(subject)
+ .to be_json_eql("The original work package".to_json)
+ .at_path("_embedded/attributesByTimestamp/0/subject")
+ expect(subject)
+ .to have_json_path("_embedded/attributesByTimestamp/1")
+ end
+
+ it 'does not embed the attributes in attributesByTimestamp if they are the same as the current attributes' do
+ expect(subject)
+ .not_to have_json_path("_embedded/attributesByTimestamp/0/description")
+ expect(subject)
+ .not_to have_json_path("_embedded/attributesByTimestamp/1/description")
+ end
+
+ describe '_meta' do
+ describe 'timestamp' do
+ it 'has the relative timestamps' do
+ expect(subject)
+ .to be_json_eql('2015-01-01T00:00:00Z'.to_json)
+ .at_path('_embedded/attributesByTimestamp/0/_meta/timestamp')
+ expect(subject)
+ .to be_json_eql('PT0S'.to_json)
+ .at_path('_embedded/attributesByTimestamp/1/_meta/timestamp')
+ end
+ end
+ end
+ end
+
describe "when the work package has not been present at the baseline time" do
let(:timestamps) { [Timestamp.parse('2015-01-01T00:00:00Z'), Timestamp.now] }
let(:created_at) { 10.days.ago }